fix: prevent 'running' status deadlock in worker

** Problem:
- Worker set processor status to 'running' BEFORE checking capacity
- If capacity limit reached, processor was skipped but status stuck at 'running'
- Worker would skip processors with 'running' status on next poll (deadlock)

** Root Cause:
- Line 591-600: update_processor_progress(..., 'running')
- Line 1434: check capacity (TOO LATE!)
- Result: status='running' but processor never started

** Fix:
- Move capacity check BEFORE setting 'running' status
- If capacity limit reached, mark as 'skipped' immediately
- Prevents 'running' status from being set when processor won't actually run

** Impact:
- Fixes UI 'Deep Scan' deadlock issue
- Workers will no longer get stuck in infinite loop
- Processor status will accurately reflect actual state

** Files Changed:
- src/worker/job_worker.rs: Moved capacity check to line 591-592
- Removed duplicate capacity check at line 1464-1493
This commit is contained in:
Accusys
2026-09-18 03:53:39 +08:00
parent 31d1b4050f
commit 0fe09afdb6
2 changed files with 35 additions and 37 deletions
+3 -3
View File
@@ -1,9 +1,9 @@
{
"filter_config": {
"face": {
"min_capture_quality": 25,
"min_confidence": 55,
"min_size": 40
"min_capture_quality": 0.25,
"min_confidence": 0.4,
"min_size": 5
}
},
"llm_config": {
+32 -34
View File
@@ -588,7 +588,37 @@ impl JobWorker {
let mut started_count = 0i32;
for processor_type in &processors_to_run {
// Update processor status to running
// Check capacity BEFORE setting status to 'running'
if !self.processor_pool.can_start_for_job(job.id).await {
info!(
"Max concurrent processors reached before starting {}, marking as skipped",
processor_type.as_str()
);
if let Err(e) = self
.db
.upsert_processor_result(job.id, *processor_type, &job.uuid, "skipped")
.await
{
error!("Failed to create skipped processor result: {}", e);
}
let _ = self
.redis
.update_worker_processor_status(
&job.uuid,
processor_type.as_str(),
"skipped",
None,
0,
0,
0,
0,
0,
)
.await;
continue;
}
// Update processor status to running (only after capacity check passes)
self.db
.update_processor_progress(
&job.uuid,
@@ -1427,41 +1457,9 @@ impl JobWorker {
}
debug!(
"Checking capacity before starting {}",
"Starting {} (capacity check already done)",
processor_type.as_str()
);
// Check capacity before starting processor
if !self.processor_pool.can_start_for_job(job.id).await {
info!(
"Max concurrent processors reached, skipping remaining processors for job {}",
job.uuid
);
// 為所有未啟動的 processors 創建 Skipped 記錄
for skipped_type in processors_to_run.iter().skip(started_count as usize) {
if let Err(e) = self
.db
.upsert_processor_result(job.id, *skipped_type, &job.uuid, "skipped")
.await
{
error!("Failed to create skipped processor result: {}", e);
}
let _ = self
.redis
.update_worker_processor_status(
&job.uuid,
skipped_type.as_str(),
"skipped",
None,
0,
0,
0,
0,
0,
)
.await;
}
break;
}
// 備份既有輸出檔(copy + timestamp suffix,不刪原檔)
let uuid = &job.uuid;