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()?;