fix: worker detects deleted jobs and skips them

When a job is deleted from the database (e.g., by unregister),
the worker now checks if the job still exists before processing.
If the job no longer exists, it skips it instead of getting stuck.

This fixes the issue where unregistering a file would leave the
worker stuck trying to process a non-existent job.
This commit is contained in:
Accusys
2026-07-06 10:28:11 +08:00
parent 799ede5a0e
commit 221aa4c4cc

View File

@@ -278,6 +278,13 @@ impl JobWorker {
} }
async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> { 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?;
if current_job.is_none() {
info!("Job {} no longer exists in database (possibly unregistered), skipping", job.uuid);
return Ok(());
}
info!("Processing job: {} ({})", job.uuid, job.id); info!("Processing job: {} ({})", job.uuid, job.id);
// Determine which processors to run based on job.processors field // Determine which processors to run based on job.processors field
@@ -1833,6 +1840,19 @@ impl JobWorker {
// 🚀 P4 Trigger: TKG Build (Face + ASRX) → then Rule2 ingestion // 🚀 P4 Trigger: TKG Build (Face + ASRX) → then Rule2 ingestion
if has_face && has_asrx { if has_face && has_asrx {
// Guard: only spawn TKG if nodes don't exist yet
let tkg_nodes_table = schema::table_name("tkg_nodes");
let tkg_exists: bool = sqlx::query_scalar::<_, i32>(&format!(
"SELECT 1 FROM {tkg_nodes_table} WHERE file_uuid = $1 LIMIT 1"
))
.bind(uuid)
.fetch_optional(self.db.pool())
.await?
.unwrap_or(0) > 0;
if tkg_exists {
info!("✅ TKG already built for {}, skipping", uuid);
} else {
info!("📝 Prerequisites met for TKG Build. Starting graph construction..."); info!("📝 Prerequisites met for TKG Build. Starting graph construction...");
let db_clone = self.db.clone(); let db_clone = self.db.clone();
let redis_clone = self.redis.clone(); let redis_clone = self.redis.clone();
@@ -1867,6 +1887,7 @@ impl JobWorker {
} }
}); });
} }
}
if !Self::ingestion_complete(self.db.pool(), uuid, job_processors).await { if !Self::ingestion_complete(self.db.pool(), uuid, job_processors).await {
info!( info!(