From 84a784834e5fb4044597e90cbc98f483b6ea7233 Mon Sep 17 00:00:00 2001 From: Irevoire Date: Wed, 17 Aug 2022 19:25:05 +0200 Subject: [PATCH] retry downloading the benchmarks datasets --- benchmarks/build.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/benchmarks/build.rs b/benchmarks/build.rs index c15123b37..d7b99db37 100644 --- a/benchmarks/build.rs +++ b/benchmarks/build.rs @@ -80,7 +80,7 @@ fn main() -> anyhow::Result<()> { } let url = format!("{}/{}.{}.gz", BASE_URL, dataset, extension); eprintln!("downloading: {}", url); - let bytes = download_dataset(url.clone())?; + let bytes = retry(|| download_dataset(url.clone()), 10)?; eprintln!("{} downloaded successfully", url); eprintln!("uncompressing in {}", out_file.display()); uncompress_in_file(bytes, &out_file)?; @@ -89,6 +89,15 @@ fn main() -> anyhow::Result<()> { Ok(()) } +fn retry(fun: impl Fn() -> Result, times: usize) -> Result { + for _ in 0..times { + if let ok @ Ok(_) = fun() { + return ok; + } + } + fun() +} + fn download_dataset(url: U) -> anyhow::Result> { let bytes = reqwest::blocking::Client::builder().timeout(None).build()?.get(url).send()?.bytes()?;