refactor(config): move verify_config_initialization with backoff retry (#4952)

This commit is contained in:
Sline
2025-10-07 07:31:35 +08:00
committed by GitHub
parent cb15a38cb3
commit b20b30baad
2 changed files with 71 additions and 77 deletions

View File

@@ -66,7 +66,7 @@ pub fn resolve_setup_async() {
init_verge_config().await;
// 添加配置验证,确保运行时配置已正确生成
verify_config_initialization().await;
Config::verify_config_initialization().await;
init_core_manager().await;
@@ -195,81 +195,6 @@ pub(super) async fn init_auto_lightweight_mode() {
logging_error!(Type::Setup, true, auto_lightweight_mode_init().await);
}
/// 验证配置初始化是否成功
async fn verify_config_initialization() {
logging!(
info,
Type::Setup,
true,
"Verifying config initialization..."
);
// 检查运行时配置是否已正确生成
if Config::runtime().await.latest_ref().config.is_some() {
logging!(
info,
Type::Setup,
true,
"Config initialization verified successfully"
);
return;
}
logging!(
warn,
Type::Setup,
true,
"Runtime config not found, regenerating..."
);
// 尝试重新生成配置最多3次
for attempt in 1..=3 {
logging!(
info,
Type::Setup,
true,
"Attempt {}/3 to regenerate config...",
attempt
);
match Config::generate().await {
Ok(_) => {
logging!(
info,
Type::Setup,
true,
"Config successfully regenerated on attempt {}",
attempt
);
return;
}
Err(e) => {
logging!(
warn,
Type::Setup,
true,
"Failed to generate config on attempt {}: {}",
attempt,
e
);
if attempt == 3 {
logging!(
error,
Type::Setup,
true,
"Failed to generate config after 3 attempts"
);
return;
}
// 等待一段时间再重试
tokio::time::sleep(tokio::time::Duration::from_millis(100 * attempt as u64)).await;
}
}
}
}
pub async fn init_work_config() {
logging!(
info,