fix(saas): fix Box<dyn Error> to anyhow conversion in cache init
This commit is contained in:
@@ -61,6 +61,24 @@ async fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化缓存并启动定时刷新 (60s)
|
||||
state.cache.load_from_db(&db).await.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
info!("Cache initialized: {} providers, {} models", state.cache.providers.len(), state.cache.models.len());
|
||||
{
|
||||
let cache_state = state.clone();
|
||||
let db_clone = db.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(60));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if let Err(e) = cache_state.cache.load_from_db(&db_clone).await {
|
||||
tracing::warn!("Cache refresh failed: {}", e);
|
||||
}
|
||||
cache_state.cache.calibrate_queue_counts(&db_clone).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let app = build_router(state).await;
|
||||
|
||||
// 配置 TCP keepalive + 短 SO_LINGER,防止 CLOSE_WAIT 累积
|
||||
|
||||
Reference in New Issue
Block a user