From fb81aa10c1d82d5005963e2eaa1394bfbcbcfe0f Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 12 May 2026 13:29:43 +0200 Subject: [PATCH] feat: enable TMDb enrichment with conditional event handling --- crates/worker/src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/worker/src/main.rs b/crates/worker/src/main.rs index 3d8a458..7924e6c 100644 --- a/crates/worker/src/main.rs +++ b/crates/worker/src/main.rs @@ -63,28 +63,33 @@ async fn main() -> anyhow::Result<()> { }; // ── Enrichment ──────────────────────────────────────────────────────────── + // Both the event handler and the staleness job are gated on TMDB_API_KEY. + // Without a key, no MovieEnrichmentRequested events are produced or handled. - let enrichment_handler: Option> = + let (enrichment_handler, enrichment_job): (Option>, Option>) = match tmdb_enrichment::TmdbEnrichmentClient::from_env() { Ok(client) => { tracing::info!("TMDb enrichment enabled"); - Some(Arc::new(tmdb_enrichment::EnrichmentHandler { + let handler = Arc::new(tmdb_enrichment::EnrichmentHandler { enrichment_client: Arc::new(client), profile_repo: Arc::clone(&ctx.movie_profile_repository), - })) + }) as Arc; + let job = Arc::new(application::jobs::EnrichmentStalenessJob::new(ctx.clone())) + as Arc; + (Some(handler), Some(job)) } Err(e) => { tracing::warn!("TMDb enrichment disabled: {e}"); - None + (None, None) } }; // ── Periodic jobs ───────────────────────────────────────────────────────── - let periodic_jobs: Vec> = vec![ + let mut periodic_jobs: Vec> = vec![ Arc::new(application::jobs::ImportSessionCleanupJob::new(ctx.clone())), - Arc::new(application::jobs::EnrichmentStalenessJob::new(ctx.clone())), ]; + if let Some(job) = enrichment_job { periodic_jobs.push(job); } for job in periodic_jobs { tokio::spawn(async move {