diff --git a/src/worker/job_worker.rs b/src/worker/job_worker.rs index 5ef119ca..2a6fcc0d 100644 --- a/src/worker/job_worker.rs +++ b/src/worker/job_worker.rs @@ -1154,6 +1154,7 @@ impl JobWorker { ); // Special handling for ASR: read status from output JSON + // Fallback: if no status field but has segments, infer "has_transcript" let mut asr_status_value: Option = None; if processor_type == crate::core::db::ProcessorType::Asrx { if let Ok(json_str) = std::fs::read_to_string(&output_path) { @@ -1164,6 +1165,26 @@ impl JobWorker { "[AUTO-REPAIR] ASR status from file: {}", status ); + } else { + // Legacy file without status: infer from segments + let seg_count = json_val.get("segments") + .and_then(|s| s.as_array()) + .map(|a| a.len()) + .unwrap_or(0); + if seg_count > 0 { + asr_status_value = Some("has_transcript".to_string()); + info!( + "[AUTO-REPAIR] ASR status inferred from {} segments: has_transcript", + seg_count + ); + // Backfill the status into the JSON file + let mut patched = json_val.clone(); + patched["status"] = serde_json::Value::String("has_transcript".to_string()); + patched["segment_count"] = serde_json::Value::Number(seg_count.into()); + if let Ok(updated) = serde_json::to_string_pretty(&patched) { + let _ = std::fs::write(&output_path, updated); + } + } } } } @@ -1182,12 +1203,13 @@ impl JobWorker { crate::core::db::ProcessorType::Asrx => { // Update asr_status from JSON if let Some(asr_status) = asr_status_value.clone() { - let status_enum = match asr_status.as_str() { - "no_audio_track" => crate::core::processor::AsrStatus::NoAudioTrack, - "silent_audio" => crate::core::processor::AsrStatus::SilentAudio, - _ => crate::core::processor::AsrStatus::SilentAudio, + let (status_enum, seg_count) = match asr_status.as_str() { + "no_audio_track" => (crate::core::processor::AsrStatus::NoAudioTrack, 0), + "silent_audio" => (crate::core::processor::AsrStatus::SilentAudio, 0), + "has_transcript" => (crate::core::processor::AsrStatus::HasTranscript, 1), + _ => (crate::core::processor::AsrStatus::SilentAudio, 0), }; - if let Err(e) = self.db.update_asr_status(result_id, &status_enum, 0).await { + if let Err(e) = self.db.update_asr_status(result_id, &status_enum, seg_count).await { warn!("[AUTO-REPAIR] Failed to update asr_status for {}: {}", job.uuid, e); } else { info!("[AUTO-REPAIR] Updated asr_status to '{}' for {}", asr_status, job.uuid);