fix: add retry strategy in tabby download (#285)

sweep/improve-logging-information
Meng Zhang 2023-07-09 13:18:19 +08:00 committed by GitHub
parent 62e0ea91d4
commit e822d1857f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 6 deletions

12
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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(())

View File

@ -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;
};