diff --git a/libs/service/agent/sync.rs b/libs/service/agent/sync.rs index 3e743f7..96fd955 100644 --- a/libs/service/agent/sync.rs +++ b/libs/service/agent/sync.rs @@ -14,6 +14,7 @@ use std::time::Duration; use tokio::time::interval; use tokio::task::JoinHandle; +use slog::Logger; use crate::AppService; use crate::error::AppError; @@ -506,7 +507,7 @@ impl AppService { match upsert_version(&self.db, model_record.id).await { Ok(v) => v, Err(e) => { - tracing::warn!("sync_upstream_models: upsert_version error: {:?}", e); + slog::warn!(self.logs, "{}", format!("sync_upstream_models: upsert_version error: {:?}", e)); continue; } }; @@ -515,7 +516,7 @@ impl AppService { } if let Err(e) = upsert_pricing(&self.db, version_record.id, or_model.pricing.as_ref()).await { - tracing::warn!("sync_upstream_models: upsert_pricing error: {:?}", e); + slog::warn!(self.logs, "{}", format!("sync_upstream_models: upsert_pricing error: {:?}", e)); } else { pricing_created += 1; } @@ -546,22 +547,23 @@ impl AppService { /// Failures are logged but do not stop the task — it keeps retrying. pub fn start_sync_task(self) -> JoinHandle<()> { let db = self.db.clone(); + let log = self.logs.clone(); tokio::spawn(async move { // Run once immediately on startup before taking traffic. - Self::sync_once(&db).await; + Self::sync_once(&db, &log).await; let mut tick = interval(Duration::from_secs(60 * 10)); loop { tick.tick().await; - Self::sync_once(&db).await; + Self::sync_once(&db, &log).await; } }) } /// Perform a single sync pass. Errors are logged and silently swallowed /// so the periodic task never stops. - async fn sync_once(db: &AppDatabase) { + async fn sync_once(db: &AppDatabase, log: &Logger) { let client = reqwest::Client::new(); let resp = match client .get("https://openrouter.ai/api/v1/models") @@ -572,17 +574,17 @@ impl AppService { Ok(resp) => match resp.json::().await { Ok(resp) => resp, Err(e) => { - tracing::error!("OpenRouter model sync: failed to parse response: {}", e); + slog::error!(log, "{}", format!("OpenRouter model sync: failed to parse response: {}", e)); return; } }, Err(e) => { - tracing::error!("OpenRouter model sync: API error: {}", e); + slog::error!(log, "{}", format!("OpenRouter model sync: API error: {}", e)); return; } }, Err(e) => { - tracing::error!("OpenRouter model sync: request failed: {}", e); + slog::error!(log, "{}", format!("OpenRouter model sync: request failed: {}", e)); return; } }; @@ -603,7 +605,7 @@ impl AppService { let provider = match upsert_provider(db, provider_slug).await { Ok(p) => p, Err(e) => { - tracing::warn!("OpenRouter model sync: upsert_provider error: {:?}", e); + slog::warn!(log, "{}", format!("OpenRouter model sync: upsert_provider error: {:?}", e)); continue; } }; @@ -618,7 +620,7 @@ impl AppService { m } Err(e) => { - tracing::warn!("OpenRouter model sync: upsert_model error: {:?}", e); + slog::warn!(log, "{}", format!("OpenRouter model sync: upsert_model error: {:?}", e)); continue; } }; @@ -626,7 +628,7 @@ impl AppService { let (version_record, version_is_new) = match upsert_version(db, model_record.id).await { Ok(v) => v, Err(e) => { - tracing::warn!("OpenRouter model sync: upsert_version error: {:?}", e); + slog::warn!(log, "{}", format!("OpenRouter model sync: upsert_version error: {:?}", e)); continue; } }; @@ -654,15 +656,17 @@ impl AppService { } } - tracing::info!( - "OpenRouter model sync complete: created={} updated={} \ - versions={} pricing={} capabilities={} profiles={}", - models_created, - models_updated, - versions_created, - pricing_created, - capabilities_created, - profiles_created + slog::info!(log, "{}", + format!( + "OpenRouter model sync complete: created={} updated={} \ + versions={} pricing={} capabilities={} profiles={}", + models_created, + models_updated, + versions_created, + pricing_created, + capabilities_created, + profiles_created + ) ); } }