From b583946f7ee1d4967c95a347c5eecf9651a4ad0e Mon Sep 17 00:00:00 2001 From: Accusys Date: Wed, 18 Nov 2026 16:08:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20per-library=20output=20path=20for=20face?= =?UTF-8?q?=5Ftrace=20spawn=20check=20+=20completeness=20check=20-=20face?= =?UTF-8?q?=5Ftrace=20spawn=20=E6=94=B9=E7=94=A8=20get=5Foutput=5Fdir=5Ffo?= =?UTF-8?q?r=5Ffile=20=E6=AA=A2=E6=9F=A5=20face=5Ftraced.json=20-=20comple?= =?UTF-8?q?teness=20check=20=E6=94=B9=E7=94=A8=20per-library=20dir=20+=20g?= =?UTF-8?q?lobal=20fallback=20-=20rust=5Fstore=5Ftraced=5Ffaces=20output?= =?UTF-8?q?=5Fdir=20=E6=94=B9=E7=94=A8=20get=5Foutput=5Fdir=5Ffor=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/worker/job_worker.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) 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