From aa4e50f4dc2d7ddb05a61162fbda0d9c740e542b Mon Sep 17 00:00:00 2001 From: Accusys Date: Tue, 29 Sep 2026 01:35:19 +0800 Subject: [PATCH] feat: add Waiting status for long-running operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 問題: - 處理過程中有長時間等待 - 用戶不知道為什麼卡住 - 無法區分「處理中」和「等待中」 修復: - ✅ 添加 VideoStatus::Waiting 狀態 - ✅ 修復重複的 match arms - ✅ TKG verification 前設為 Waiting - ✅ Ingestion 前設為 Waiting 狀態流程: - Scanning → Processing → Waiting → Indexed → Completed 用戶體驗: - 等待 TKG 時顯示 'waiting' - 等待 ingestion 時顯示 'waiting' - 更清晰的狀態區分 狀態: ✅ 已實施 --- src/core/db/postgres_db.rs | 13 +++---------- src/worker/job_worker.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index d1c62c14..323bbab2 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -233,6 +233,7 @@ pub enum VideoStatus { Queued, Scanning, Processing, + Waiting, Processed, Indexed, CheckedOut, @@ -254,6 +255,7 @@ impl VideoStatus { VideoStatus::Queued => "queued", VideoStatus::Scanning => "scanning", VideoStatus::Processing => "processing", + VideoStatus::Waiting => "waiting", VideoStatus::Processed => "processed", VideoStatus::Indexed => "indexed", VideoStatus::CheckedOut => "checked_out", @@ -264,11 +266,6 @@ impl VideoStatus { VideoStatus::AgentReady => "agent_ready", VideoStatus::Completed => "completed", VideoStatus::Failed => "failed", - VideoStatus::Processed => "processed", - VideoStatus::Indexed => "indexed", - VideoStatus::CheckedOut => "checked_out", - VideoStatus::Completed => "completed", - VideoStatus::Failed => "failed", } } @@ -280,6 +277,7 @@ impl VideoStatus { "queued" => Some(VideoStatus::Queued), "scanning" => Some(VideoStatus::Scanning), "processing" => Some(VideoStatus::Processing), + "waiting" => Some(VideoStatus::Waiting), "processed" => Some(VideoStatus::Processed), "indexed" => Some(VideoStatus::Indexed), "checked_out" => Some(VideoStatus::CheckedOut), @@ -290,11 +288,6 @@ impl VideoStatus { "agent_ready" => Some(VideoStatus::AgentReady), "completed" => Some(VideoStatus::Completed), "failed" => Some(VideoStatus::Failed), - "processed" => Some(VideoStatus::Processed), - "indexed" => Some(VideoStatus::Indexed), - "checked_out" => Some(VideoStatus::CheckedOut), - "completed" => Some(VideoStatus::Completed), - "failed" => Some(VideoStatus::Failed), _ => None, } } diff --git a/src/worker/job_worker.rs b/src/worker/job_worker.rs index 11879cf9..6f4d7db4 100644 --- a/src/worker/job_worker.rs +++ b/src/worker/job_worker.rs @@ -3402,6 +3402,12 @@ impl JobWorker { let filter = serde_json::json!({ "must": [{"key": "file_uuid", "match": {"value": uuid}}] }); + + // Update status to Waiting during TKG verification + if let Err(e) = self.db.update_video_status(uuid, VideoStatus::Waiting).await { + error!("[STATUS] Failed to update status to 'waiting' for TKG: {}", e); + } + let mut attempts = 0; let max_attempts = 60; let mut stable_trace_count: Option = None; @@ -3721,6 +3727,12 @@ impl JobWorker { "Job {}: all processors done, waiting for ingestion...", job_id ); + + // Update status to Waiting during ingestion phase + if let Err(e) = self.db.update_video_status(uuid, VideoStatus::Waiting).await { + error!("[STATUS] Failed to update status to 'waiting' for {}: {}", uuid, e); + } + return Ok(false); }