fix: add retry strategy in tabby download (#285)
parent
62e0ea91d4
commit
e822d1857f
|
|
@ -2828,6 +2828,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serdeconv",
|
"serdeconv",
|
||||||
"tabby-common",
|
"tabby-common",
|
||||||
|
"tokio-retry",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -3151,6 +3152,17 @@ dependencies = [
|
||||||
"tokio",
|
"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]]
|
[[package]]
|
||||||
name = "tokio-stream"
|
name = "tokio-stream"
|
||||||
version = "0.1.14"
|
version = "0.1.14"
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,4 @@ reqwest = { version = "0.11.18", features = ["stream", "json"] }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serdeconv = { workspace = true }
|
serdeconv = { workspace = true }
|
||||||
|
tokio-retry = "0.3.0"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ use cache_info::CacheInfo;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use tabby_common::path::ModelDir;
|
use tabby_common::path::ModelDir;
|
||||||
|
use tokio_retry::{
|
||||||
|
strategy::{jitter, ExponentialBackoff},
|
||||||
|
Retry,
|
||||||
|
};
|
||||||
|
|
||||||
impl CacheInfo {
|
impl CacheInfo {
|
||||||
async fn download(
|
async fn download(
|
||||||
|
|
@ -41,7 +45,11 @@ impl CacheInfo {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !local_file_ready {
|
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;
|
self.set_local_cache_key(path, &etag).await;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -148,12 +148,13 @@ mod tags {
|
||||||
let empty = Vec::new();
|
let empty = Vec::new();
|
||||||
|
|
||||||
let Some(config) = config else {
|
let Some(config) = config else {
|
||||||
return empty;
|
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)
|
||||||
return empty;
|
else {
|
||||||
};
|
return empty;
|
||||||
|
};
|
||||||
|
|
||||||
if has_error {
|
if has_error {
|
||||||
return empty;
|
return empty;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue