fix: replace hardcoded store_traced_faces.py with Rust binary
- Worker was calling Python store_traced_faces.py instead of Rust version - This caused trace_id=0 in Qdrant, blocking TKG and file completion - Now uses rust_binary_path() to find and execute rust_store_traced_faces - Also removed all Python implementations from processor config - Removed POSE processor (deprecated) - Added redis_publisher.py symlink for face clustering Fixed: file stuck in 'Scanning' due to trace stability check failure
This commit is contained in:
+71
-70
@@ -830,9 +830,12 @@ impl JobWorker {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
// Check if job still exists in database (may have been deleted by unregister)
|
||||
let current_job = self.db.get_monitor_job_by_uuid(&job.uuid).await?;
|
||||
async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
let job_id = job.id;
|
||||
let uuid = job.uuid.clone();
|
||||
|
||||
// Check if job still exists in database (may have been deleted by unregister)
|
||||
let current_job = self.db.get_monitor_job_by_uuid(&job.uuid).await?;
|
||||
if current_job.is_none() {
|
||||
info!(
|
||||
"Job {} no longer exists in database (possibly unregistered), skipping",
|
||||
@@ -988,7 +991,7 @@ impl JobWorker {
|
||||
);
|
||||
if let Err(e) = self
|
||||
.db
|
||||
.upsert_processor_result(job.id, *processor_type, &job.uuid, "skipped")
|
||||
.upsert_processor_result(job_id, *processor_type, &job.uuid, "skipped")
|
||||
.await
|
||||
{
|
||||
error!("Failed to create skipped processor result: {}", e);
|
||||
@@ -1129,7 +1132,7 @@ impl JobWorker {
|
||||
for attempt in 1..=3 {
|
||||
match self
|
||||
.db
|
||||
.upsert_processor_result(job.id, *processor_type, &job.uuid, "completed")
|
||||
.upsert_processor_result(job_id, *processor_type, &job.uuid, "completed")
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
@@ -1599,7 +1602,7 @@ impl JobWorker {
|
||||
);
|
||||
if let Err(e) = self
|
||||
.db
|
||||
.upsert_processor_result(job.id, *processor_type, &job.uuid, "pending")
|
||||
.upsert_processor_result(job_id, *processor_type, &job.uuid, "pending")
|
||||
.await
|
||||
{
|
||||
error!(
|
||||
@@ -1849,7 +1852,7 @@ impl JobWorker {
|
||||
// 創建 skipped 記錄讓 job 可以正確完成
|
||||
if let Err(e) = self
|
||||
.db
|
||||
.upsert_processor_result(job.id, *processor_type, &job.uuid, "skipped")
|
||||
.upsert_processor_result(job_id, *processor_type, &job.uuid, "skipped")
|
||||
.await
|
||||
{
|
||||
error!("Failed to create skipped processor result: {}", e);
|
||||
@@ -1946,7 +1949,7 @@ impl JobWorker {
|
||||
|
||||
let processor_result_id = self
|
||||
.db
|
||||
.upsert_processor_result(job.id, *processor_type, &job.uuid, "pending")
|
||||
.upsert_processor_result(job_id, *processor_type, &job.uuid, "pending")
|
||||
.await?;
|
||||
|
||||
info!(
|
||||
@@ -3140,6 +3143,29 @@ impl JobWorker {
|
||||
|
||||
if trace_complete {
|
||||
info!("✅ Face trace already done for {}, skipping spawn", uuid);
|
||||
|
||||
// ✅ Ensure processor_results record exists for dependency checks
|
||||
let mut success = false;
|
||||
for attempt in 1..=3 {
|
||||
match self
|
||||
.db
|
||||
.upsert_processor_result(job_id, crate::core::db::ProcessorType::FaceTrace, &uuid, "completed")
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
success = true;
|
||||
info!("✅ Created processor_results record for face_trace (already done)");
|
||||
break;
|
||||
}
|
||||
Err(e) if attempt < 3 => {
|
||||
warn!("⚠️ Failed to create processor_results for face_trace (attempt {}): {}", attempt, e);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
}
|
||||
Err(e) => {
|
||||
error!("❌ Failed to create processor_results for face_trace after 3 attempts: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fast-path for no-face videos: face.json reports no_faces, so
|
||||
// writing face_traced.json directly avoids spawning
|
||||
@@ -3218,6 +3244,12 @@ impl JobWorker {
|
||||
"⚡ No-face fast-path: wrote {} for {} (skipping face-trace spawn)",
|
||||
traced_path, uuid
|
||||
);
|
||||
|
||||
// ✅ Create processor_results record for dependency checks
|
||||
let _ = self
|
||||
.db
|
||||
.upsert_processor_result(job_id, crate::core::db::ProcessorType::FaceTrace, &uuid, "completed")
|
||||
.await;
|
||||
} else {
|
||||
warn!(
|
||||
"⚠️ Failed to write no-face fast-path face_traced.json for {}",
|
||||
@@ -3276,6 +3308,7 @@ impl JobWorker {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
// Use Rust binary for face trace store (V3 config: priority 0)
|
||||
let executor = match crate::core::processor::PythonExecutor::new() {
|
||||
Ok(ex) => ex,
|
||||
Err(e) => {
|
||||
@@ -3287,17 +3320,33 @@ impl JobWorker {
|
||||
return;
|
||||
}
|
||||
};
|
||||
match executor
|
||||
.run_with_output_idx(
|
||||
"store_traced_faces.py",
|
||||
&["--file-uuid", &uuid_clone],
|
||||
Some(&uuid_clone),
|
||||
"TRACE_STORE",
|
||||
Some(std::time::Duration::from_secs(600)),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
let result = match executor.rust_binary_path("rust_store_traced_faces") {
|
||||
Some(bin) => {
|
||||
tracing::info!("[FACE_TRACE] Using Rust binary: {:?}", bin);
|
||||
executor
|
||||
.run_rust_with_output_idx_and_frames(
|
||||
&bin,
|
||||
&[&uuid_clone, "--output-dir", output_dir],
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
"TRACE_STORE",
|
||||
Some(std::time::Duration::from_secs(600)),
|
||||
)
|
||||
.await
|
||||
}
|
||||
None => {
|
||||
tracing::warn!(
|
||||
"[FACE_TRACE] rust_store_traced_faces binary not found, skipping face tracing"
|
||||
);
|
||||
Err(anyhow::anyhow!("rust_store_traced_faces binary not found"))
|
||||
}
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
info!(
|
||||
"✅ Face trace + DB store completed for {}",
|
||||
@@ -3485,58 +3534,10 @@ impl JobWorker {
|
||||
"📝 Face dedup waiting: face_traced.json not yet ready for {}",
|
||||
uuid
|
||||
);
|
||||
} else {
|
||||
// Verify trace profiles have required files (sample check)
|
||||
if let Ok(content) = std::fs::read_to_string(&traced_path) {
|
||||
if let Ok(traced_data) = serde_json::from_str::<serde_json::Value>(&content)
|
||||
{
|
||||
if let Some(traces) = traced_data.get("traces") {
|
||||
let trace_ids: Vec<i64> = if traces.is_object() {
|
||||
traces
|
||||
.as_object()
|
||||
.map(|o| o.keys().filter_map(|k| k.parse().ok()).collect())
|
||||
.unwrap_or_default()
|
||||
} else if traces.is_array() {
|
||||
traces
|
||||
.as_array()
|
||||
.map(|a| {
|
||||
a.iter()
|
||||
.filter_map(|v| {
|
||||
v.get("trace_id").and_then(|t| t.as_i64())
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
// Sample first 5 traces to verify required files
|
||||
let sample_size = trace_ids.len().min(5);
|
||||
let mut missing_count = 0;
|
||||
for &tid in trace_ids.iter().take(sample_size) {
|
||||
let trace_dir =
|
||||
crate::core::file_profile::FaceTraceProfile::trace_dir(
|
||||
output_dir, &uuid, tid,
|
||||
);
|
||||
if !trace_dir.join("key_frame.jpg").exists() {
|
||||
missing_count += 1;
|
||||
}
|
||||
if !trace_dir.join("key_face.jpg").exists() {
|
||||
missing_count += 1;
|
||||
}
|
||||
if !trace_dir.join("trace_profile.json").exists() {
|
||||
missing_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if missing_count > 0 {
|
||||
info!("📝 Face dedup waiting: {} missing files in trace sample for {} (TKG may still be building)", missing_count, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ✅ Simplified: Only check face_traced.json existence
|
||||
// Trace directories (key_frame.jpg, key_face.jpg, trace_profile.json)
|
||||
// are optional - face_cluster can work with face_traced.json alone
|
||||
|
||||
let face_cluster_path = format!("{}/{}.face_cluster.json", output_dir, uuid);
|
||||
if std::path::Path::new(&face_cluster_path).exists() {
|
||||
|
||||
Reference in New Issue
Block a user