diff --git a/Cargo.lock b/Cargo.lock index fed0ccb..6d90f43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2828,6 +2828,7 @@ dependencies = [ "serde", "serdeconv", "tabby-common", + "tokio-retry", ] [[package]] @@ -3151,6 +3152,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-retry" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" +dependencies = [ + "pin-project", + "rand", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" diff --git a/crates/tabby-download/Cargo.toml b/crates/tabby-download/Cargo.toml index fd52341..d33ca8c 100644 --- a/crates/tabby-download/Cargo.toml +++ b/crates/tabby-download/Cargo.toml @@ -11,3 +11,4 @@ reqwest = { version = "0.11.18", features = ["stream", "json"] } anyhow = { workspace = true } serde = { workspace = true } serdeconv = { workspace = true } +tokio-retry = "0.3.0" diff --git a/crates/tabby-download/src/lib.rs b/crates/tabby-download/src/lib.rs index 291f476..ac247e3 100644 --- a/crates/tabby-download/src/lib.rs +++ b/crates/tabby-download/src/lib.rs @@ -7,6 +7,10 @@ use cache_info::CacheInfo; use futures_util::StreamExt; use indicatif::{ProgressBar, ProgressStyle}; use tabby_common::path::ModelDir; +use tokio_retry::{ + strategy::{jitter, ExponentialBackoff}, + Retry, +}; impl CacheInfo { async fn download( @@ -41,7 +45,11 @@ impl CacheInfo { }; if !local_file_ready { - let etag = download_file(&url, &filepath, local_cache_key, is_optional).await?; + let strategy = ExponentialBackoff::from_millis(100).map(jitter).take(3); + let etag = Retry::spawn(strategy, || { + download_file(&url, &filepath, local_cache_key, is_optional) + }) + .await?; self.set_local_cache_key(path, &etag).await; } Ok(()) diff --git a/crates/tabby-scheduler/src/dataset.rs b/crates/tabby-scheduler/src/dataset.rs index 9acccb3..87d5196 100644 --- a/crates/tabby-scheduler/src/dataset.rs +++ b/crates/tabby-scheduler/src/dataset.rs @@ -148,12 +148,13 @@ mod tags { let empty = Vec::new(); let Some(config) = config else { - return empty; - }; + return empty; + }; - let Ok((tags, has_error)) = context.generate_tags(&config.0, content.as_bytes(), None) else { - return empty; - }; + let Ok((tags, has_error)) = context.generate_tags(&config.0, content.as_bytes(), None) + else { + return empty; + }; if has_error { return empty;