From defe0469ab994b244d8f70e0fb7aa8f17961397f Mon Sep 17 00:00:00 2001 From: sim1222 Date: Thu, 18 Jul 2024 11:08:07 +0900 Subject: [PATCH] implement retry --- src/main.rs | 64 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4d5c60e..398cede 100644 --- a/src/main.rs +++ b/src/main.rs @@ -432,32 +432,46 @@ async fn multipart_upload( } else { chunk_size }; - let stream = ByteStream::read_from() - .path(file.file.clone()) - .offset(chunk_index * chunk_size) - .length(Length::Exact(this_chunk)) - .build() - .await - .unwrap(); - //Chunk index needs to start at 0, but part numbers start at 1. - let part_number = (chunk_index as i32) + 1; - let upload_part_res = s3_client - .upload_part() - .key(&key) - .bucket(bucket) - .upload_id(upload_id) - .body(stream) - .part_number(part_number) - .send() - .await - .unwrap(); - upload_parts.lock().await.push( - CompletedPart::builder() - .e_tag(upload_part_res.e_tag.unwrap_or_default()) + loop { + let stream = ByteStream::read_from() + .path(file.file.clone()) + .offset(chunk_index * chunk_size) + .length(Length::Exact(this_chunk)) + .build() + .await; + let stream = match stream { + Ok(stream) => stream, + Err(e) => { + eprintln!("Error: {:?}", e); + continue; + } + }; + //Chunk index needs to start at 0, but part numbers start at 1. + let part_number = (chunk_index as i32) + 1; + let upload_part_res = s3_client + .upload_part() + .key(&key) + .bucket(bucket.clone()) + .upload_id(upload_id.clone()) + .body(stream) .part_number(part_number) - .build(), - ); - pb.inc(this_chunk); + .send() + .await; + let upload_part_res = match upload_part_res { + Ok(upload_part_res) => upload_part_res, + Err(e) => { + eprintln!("Error: {:?}", e); + continue; + } + }; + upload_parts.lock().await.push( + CompletedPart::builder() + .e_tag(upload_part_res.e_tag.unwrap_or_default()) + .part_number(part_number) + .build(), + ); + pb.inc(this_chunk); + } }); handles.push(handle); }