From 386c9aa15b72dcb52e9ad2fde1c44501e50c4cf6 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Tue, 15 Aug 2023 15:46:09 +0530 Subject: [PATCH 1/2] fix: retry only reqwest errors --- uplink/src/collector/downloader.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index a42300d6e..f01a7004b 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -179,8 +179,11 @@ impl FileDownloader { match self.run(action.clone()).await { Ok(_) => return Ok(()), Err(e) => { - error!("Download failed: {e}"); - res = Err(e); + if let Error::Reqwest(e) = e { + error!("Download failed: {e}"); + } else { + return Err(e); + } } } tokio::time::sleep(Duration::from_secs(30)).await; From 72a81f78c1faf2dc7f2b412e20bf55ba7700aa56 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Tue, 15 Aug 2023 16:08:55 +0530 Subject: [PATCH 2/2] style: clippy suggestion --- uplink/src/collector/downloader.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index f01a7004b..cd14fd397 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -174,10 +174,9 @@ impl FileDownloader { // Retry mechanism tries atleast 3 times before returning an error async fn retry_thrice(&mut self, action: Action) -> Result<(), Error> { - let mut res = Ok(()); for _ in 0..3 { match self.run(action.clone()).await { - Ok(_) => return Ok(()), + Ok(_) => break, Err(e) => { if let Error::Reqwest(e) = e { error!("Download failed: {e}"); @@ -190,7 +189,7 @@ impl FileDownloader { warn!("Retrying download"); } - res + Ok(()) } // Accepts a download `Action` and performs necessary data extraction to actually download the file