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,25 +432,38 @@ async fn multipart_upload(
} else {
chunk_size
};
loop {
let stream = ByteStream::read_from()
.path(file.file.clone())
.offset(chunk_index * chunk_size)
.length(Length::Exact(this_chunk))
.build()
.await
.unwrap();
.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)
.upload_id(upload_id)
.bucket(bucket.clone())
.upload_id(upload_id.clone())
.body(stream)
.part_number(part_number)
.send()
.await
.unwrap();
.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())
@ -458,6 +471,7 @@ async fn multipart_upload(
.build(),
);
pb.inc(this_chunk);
}
});
handles.push(handle);
}