diff --git a/src/worker/job_worker.rs b/src/worker/job_worker.rs index c9cd88d8..20461f16 100644 --- a/src/worker/job_worker.rs +++ b/src/worker/job_worker.rs @@ -589,7 +589,7 @@ impl JobWorker { async fn periodic_completeness_check(&self) -> Result<()> { info!("[COMPLETENESS] Starting periodic output completeness check"); - let output_dir = crate::core::config::OUTPUT_DIR.to_string(); + let global_output_dir = crate::core::config::OUTPUT_DIR.to_string(); let videos_table = schema::table_name("videos"); let rows: Vec<(String, String)> = sqlx::query_as(&format!( @@ -606,18 +606,31 @@ impl JobWorker { for (uuid, file_name) in &rows { let mut missing: Vec = Vec::new(); + // Use per-library output dir with fallback to global + let per_lib_dir = crate::core::config::get_output_dir_for_file(uuid, self.db.pool()).await; + // 檢查 JSON 產出 for ext in ["asrx", "cut", "face", "face_cluster", "face_traced", "ocr", "scenes"] { - let path = format!("{}/{}.{}.json", output_dir, uuid, ext); - if !std::path::Path::new(&path).exists() { + let filename = format!("{}.{}.json", uuid, ext); + let per_lib_path = format!("{}/{}", per_lib_dir.trim_end_matches('/'), filename); + let global_path = format!("{}/{}", global_output_dir.trim_end_matches('/'), filename); + if !std::path::Path::new(&per_lib_path).exists() && !std::path::Path::new(&global_path).exists() { missing.push(format!("{}.json", ext)); } } // 檢查 trace 目錄 - let trace_base = std::path::Path::new(&output_dir).join(uuid); - if trace_base.is_dir() { - if let Ok(entries) = std::fs::read_dir(&trace_base) { + let trace_base = std::path::Path::new(&per_lib_dir).join(uuid); + let trace_base_global = std::path::Path::new(&global_output_dir).join(uuid); + let effective_trace_base = if trace_base.is_dir() { + trace_base + } else if trace_base_global.is_dir() { + trace_base_global + } else { + std::path::PathBuf::new() + }; + if effective_trace_base.is_dir() { + if let Ok(entries) = std::fs::read_dir(&effective_trace_base) { for entry in entries.filter_map(|e| e.ok()) { let name = entry.file_name().to_string_lossy().to_string(); if name.starts_with("trace_") && entry.path().is_dir() { @@ -4017,11 +4030,10 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> { // Note: trigger is gated on face alone (not has_asrx) so no-face videos still // get face_traced.json written via the fast-path, unblocking FaceCluster. if has_face { + let per_lib_dir = crate::core::config::get_output_dir_for_file(uuid, self.db.pool()).await; let traced_path = format!( "{}/{}.face_traced.json", - crate::core::config::OUTPUT_DIR - .as_str() - .trim_end_matches('/'), + per_lib_dir.trim_end_matches('/'), uuid ); // ✅ V2: Check data integrity, not just file existence @@ -4215,7 +4227,8 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> { } }; - let output_dir = crate::core::config::OUTPUT_DIR.as_str(); + let output_dir = crate::core::config::get_output_dir_for_file(&uuid_clone, db_clone.pool()).await; + let output_dir = output_dir.as_str(); // Get video path from DB for face crop extraction let video_path: Option = db_clone