refactor: migrate backoff crate to backon (#6718)

Replace backoff 0.4.0 with backon 1.6.0 for retry logic.
This commit is contained in:
Tunglies
2026-04-03 13:21:04 +00:00
committed by GitHub
parent 5da9f99698
commit 830c0773dc
6 changed files with 78 additions and 92 deletions
+13 -15
View File
@@ -13,7 +13,7 @@ use crate::{
utils::{dirs, help},
};
use anyhow::{Result, anyhow};
use backoff::{Error as BackoffError, ExponentialBackoff};
use backon::{ExponentialBuilder, Retryable as _};
use clash_verge_draft::Draft;
use clash_verge_logging::{Type, logging, logging_error};
use serde_yaml_ng::{Mapping, Value};
@@ -204,23 +204,21 @@ impl Config {
}
pub async fn verify_config_initialization() {
let backoff_strategy = ExponentialBackoff {
initial_interval: std::time::Duration::from_millis(100),
max_interval: std::time::Duration::from_secs(2),
max_elapsed_time: Some(std::time::Duration::from_secs(10)),
multiplier: 2.0,
..Default::default()
};
let backoff = ExponentialBuilder::default()
.with_min_delay(std::time::Duration::from_millis(100))
.with_max_delay(std::time::Duration::from_secs(2))
.with_factor(2.0)
.with_max_times(10);
let operation = || async {
if let Err(e) = (|| async {
if Self::runtime().await.latest_arc().config.is_some() {
return Ok::<(), BackoffError<anyhow::Error>>(());
return Ok::<(), anyhow::Error>(());
}
Self::generate().await.map_err(BackoffError::transient)
};
if let Err(e) = backoff::future::retry(backoff_strategy, operation).await {
Self::generate().await
})
.retry(backoff)
.await
{
logging!(error, Type::Setup, "Config init verification failed: {}", e);
}
}