fix: register creates monitor_job with full pipeline after unregister

When a file is re-registered after unregister, the monitor_job is
missing. The register function now checks if a job exists and creates
one with full pipeline processors (cut, asr, asrx, ocr, face,
face_cluster) if missing.

This ensures re-scan after unregister triggers the complete pipeline
including face detection → TKG → VLM summary (P5).
This commit is contained in:
Accusys
2026-08-22 23:51:10 +08:00
parent 58d80e34c6
commit b8b8f2d6af
+51 -6
View File
@@ -620,6 +620,34 @@ async fn register_single_file(
let _ = std::fs::write(&probe_path, json_str);
}
// Ensure monitor_job exists with full pipeline processors.
// After unregister, the job is deleted; re-register must recreate it.
let monitor_jobs_table = schema::table_name("monitor_jobs");
let job_exists: bool = sqlx::query_scalar(&format!(
"SELECT EXISTS(SELECT 1 FROM {monitor_jobs_table} WHERE uuid = $1)"
))
.bind(&file_uuid)
.fetch_one(db.pool())
.await
.unwrap_or(false);
if !job_exists && has_video && total_frames > 0 && fps > 0.0 {
let all_procs: Vec<&str> = vec!["cut", "asr", "asrx", "ocr", "face", "face_cluster"];
let _ = db
.create_monitor_job(&file_uuid, Some(&canonical_path), None)
.await;
let total = total_frames as u64;
let _ = db.init_processing_status(&file_uuid, all_procs, total).await;
let _ = sqlx::query(&format!(
"UPDATE {} SET status = 'scanning' WHERE file_uuid = $1",
videos_table
))
.bind(&file_uuid)
.execute(db.pool())
.await;
tracing::info!("[REGISTER] Created new monitor job with full pipeline for {}", file_uuid);
}
RegisterFileResponse {
success: true,
file_uuid,
@@ -826,7 +854,11 @@ async fn register_file(
.flatten();
if let Some(ref vp) = video_path {
if let Ok(job) = auto_state.db.create_monitor_job(&auto_uuid, Some(vp), face_settings_json.as_ref()).await {
if let Ok(job) = auto_state
.db
.create_monitor_job(&auto_uuid, Some(vp), face_settings_json.as_ref())
.await
{
tracing::info!("[AUTO-PIPELINE] Job {} created for {}", job.id, auto_uuid);
let all_procs: Vec<&str> =
vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"];
@@ -1138,7 +1170,10 @@ async fn unregister(
tracing::info!(
"[UNREGISTER] Trigger: source={}, reason={}. Unregistering file: {} (async_mode={})",
source, reason, uuid, req.async_mode
source,
reason,
uuid,
req.async_mode
);
// Async mode: spawn background task and return immediately
@@ -1151,7 +1186,9 @@ async fn unregister(
tokio::spawn(async move {
tracing::info!(
"[ASYNC_UNREGISTER] Starting background unregister for {} (source={}, reason={})",
uuid_clone, source_clone, reason_clone
uuid_clone,
source_clone,
reason_clone
);
match unregister_internal(&state_clone, &uuid_clone).await {
Ok(()) => {
@@ -1160,7 +1197,10 @@ async fn unregister(
Err(e) => {
tracing::error!(
"[ASYNC_UNREGISTER] FAILED for {} (source={}, reason={}): {:?}",
uuid_clone, source_clone, reason_clone, e
uuid_clone,
source_clone,
reason_clone,
e
);
}
}
@@ -1315,7 +1355,10 @@ async fn unregister(
tx.commit().await.map_err(|e| {
tracing::error!(
"[UNREGISTER] FAILED to commit transaction for {} (source={}, reason={}): {}",
uuid, source, reason, e
uuid,
source,
reason,
e
);
StatusCode::INTERNAL_SERVER_ERROR
})?;
@@ -1420,7 +1463,9 @@ async fn unregister(
Err(e) => {
tracing::error!(
"[UNREGISTER] FAILED to create Redis client for {} (source={}): {}",
uuid, source, e
uuid,
source,
e
);
None
}