fix: add retry strategy in tabby download (#285)
parent
62e0ea91d4
commit
e822d1857f
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -151,7 +151,8 @@ mod tags {
|
|||
return empty;
|
||||
};
|
||||
|
||||
let Ok((tags, has_error)) = context.generate_tags(&config.0, content.as_bytes(), None) else {
|
||||
let Ok((tags, has_error)) = context.generate_tags(&config.0, content.as_bytes(), None)
|
||||
else {
|
||||
return empty;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue