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:
+51
-6
@@ -620,6 +620,34 @@ async fn register_single_file(
|
|||||||
let _ = std::fs::write(&probe_path, json_str);
|
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 {
|
RegisterFileResponse {
|
||||||
success: true,
|
success: true,
|
||||||
file_uuid,
|
file_uuid,
|
||||||
@@ -826,7 +854,11 @@ async fn register_file(
|
|||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
if let Some(ref vp) = video_path {
|
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);
|
tracing::info!("[AUTO-PIPELINE] Job {} created for {}", job.id, auto_uuid);
|
||||||
let all_procs: Vec<&str> =
|
let all_procs: Vec<&str> =
|
||||||
vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"];
|
vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"];
|
||||||
@@ -1138,7 +1170,10 @@ async fn unregister(
|
|||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"[UNREGISTER] Trigger: source={}, reason={}. Unregistering file: {} (async_mode={})",
|
"[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
|
// Async mode: spawn background task and return immediately
|
||||||
@@ -1151,7 +1186,9 @@ async fn unregister(
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"[ASYNC_UNREGISTER] Starting background unregister for {} (source={}, reason={})",
|
"[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 {
|
match unregister_internal(&state_clone, &uuid_clone).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
@@ -1160,7 +1197,10 @@ async fn unregister(
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"[ASYNC_UNREGISTER] FAILED for {} (source={}, reason={}): {:?}",
|
"[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| {
|
tx.commit().await.map_err(|e| {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"[UNREGISTER] FAILED to commit transaction for {} (source={}, reason={}): {}",
|
"[UNREGISTER] FAILED to commit transaction for {} (source={}, reason={}): {}",
|
||||||
uuid, source, reason, e
|
uuid,
|
||||||
|
source,
|
||||||
|
reason,
|
||||||
|
e
|
||||||
);
|
);
|
||||||
StatusCode::INTERNAL_SERVER_ERROR
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
})?;
|
})?;
|
||||||
@@ -1420,7 +1463,9 @@ async fn unregister(
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"[UNREGISTER] FAILED to create Redis client for {} (source={}): {}",
|
"[UNREGISTER] FAILED to create Redis client for {} (source={}): {}",
|
||||||
uuid, source, e
|
uuid,
|
||||||
|
source,
|
||||||
|
e
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user