implement retry

This commit is contained in:
sim1222 2024-07-18 11:08:07 +09:00
parent 1f8f25c038
commit defe0469ab
Signed by: sim1222
GPG Key ID: D1AE30E316E44E5D

View File

@ -432,32 +432,46 @@ async fn multipart_upload(
} else { } else {
chunk_size chunk_size
}; };
let stream = ByteStream::read_from() loop {
.path(file.file.clone()) let stream = ByteStream::read_from()
.offset(chunk_index * chunk_size) .path(file.file.clone())
.length(Length::Exact(this_chunk)) .offset(chunk_index * chunk_size)
.build() .length(Length::Exact(this_chunk))
.await .build()
.unwrap(); .await;
//Chunk index needs to start at 0, but part numbers start at 1. let stream = match stream {
let part_number = (chunk_index as i32) + 1; Ok(stream) => stream,
let upload_part_res = s3_client Err(e) => {
.upload_part() eprintln!("Error: {:?}", e);
.key(&key) continue;
.bucket(bucket) }
.upload_id(upload_id) };
.body(stream) //Chunk index needs to start at 0, but part numbers start at 1.
.part_number(part_number) let part_number = (chunk_index as i32) + 1;
.send() let upload_part_res = s3_client
.await .upload_part()
.unwrap(); .key(&key)
upload_parts.lock().await.push( .bucket(bucket.clone())
CompletedPart::builder() .upload_id(upload_id.clone())
.e_tag(upload_part_res.e_tag.unwrap_or_default()) .body(stream)
.part_number(part_number) .part_number(part_number)
.build(), .send()
); .await;
pb.inc(this_chunk); 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); handles.push(handle);
} }