File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020use std:: path:: Path ;
2121
2222use anyhow:: Result ;
23+ use backon:: { ExponentialBuilder , Retryable } ;
2324use tokio:: fs;
24- use tracing:: debug;
25+ use tracing:: { debug, warn } ;
2526
2627use crate :: HTTP_CLIENT ;
2728
28- /// Download file using HTTP_CLIENT without any progress tracking
29+ /// Download a file using HTTP_CLIENT without any progress tracking
2930pub async fn download_file_untracked ( url : & str , path : impl AsRef < Path > ) -> Result < ( ) > {
3031 let path = path. as_ref ( ) . to_owned ( ) ;
3132 let response = HTTP_CLIENT . get ( url) . send ( ) . await ?. error_for_status ( ) ?;
@@ -41,11 +42,17 @@ where
4142{
4243 debug ! ( "Downloading file {:?}" , url) ;
4344
44- let mut response = HTTP_CLIENT
45- . get ( url. trim ( ) )
46- . send ( )
47- . await ?
48- . error_for_status ( ) ?;
45+ let mut response = ( || async {
46+ HTTP_CLIENT
47+ . get ( url. trim ( ) )
48+ . send ( )
49+ . await ?
50+ . error_for_status ( )
51+ } ) . retry ( ExponentialBuilder :: default ( ) )
52+ . notify ( |err, dur| {
53+ warn ! ( "Failed to download file {}. Retrying in {:?}. Error: {}" , url, dur, err) ;
54+ } )
55+ . await ?;
4956
5057 debug ! ( "Response received from url" ) ;
5158
You can’t perform that action at this time.
0 commit comments