fix(proxy): reset health badges when proxy stops

Clear all provider_health records when stopping the proxy server,
ensuring health badges reset to "healthy" state. This fixes the
inconsistency where circuit breakers (in memory) would reset on
stop but health badges (in database) would retain stale state.
This commit is contained in:
Jason
2025-12-15 22:52:58 +08:00
parent 007813e09e
commit e081c7560c
2 changed files with 17 additions and 0 deletions

View File

@@ -230,6 +230,17 @@ impl Database {
Ok(())
}
/// 清空所有Provider健康状态代理停止时调用
pub async fn clear_all_provider_health(&self) -> Result<(), AppError> {
let conn = lock_conn!(self.conn);
conn.execute("DELETE FROM provider_health", [])
.map_err(|e| AppError::Database(e.to_string()))?;
log::debug!("Cleared all provider health records");
Ok(())
}
// ==================== Circuit Breaker Config ====================
/// 获取熔断器配置

View File

@@ -306,6 +306,12 @@ impl ProxyService {
.await
.map_err(|e| format!("删除备份失败: {e}"))?;
// 5. 重置健康状态(让健康徽章恢复为正常)
self.db
.clear_all_provider_health()
.await
.map_err(|e| format!("重置健康状态失败: {e}"))?;
log::info!("代理已停止Live 配置已恢复");
Ok(())
}