From bcc8c3f484a68cb58c5c6df140ee55d256939ce0 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 18 May 2026 00:30:37 +0100 Subject: [PATCH] =?UTF-8?q?notes:=20=E5=90=AF=E5=8A=A8=E6=97=B6=20resume?= =?UTF-8?q?=20=E5=8D=A1=E5=9C=A8=20transcribing/summarizing/pending=20?= =?UTF-8?q?=E7=9A=84=E5=BD=95=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pod 重启时 spawn 的 worker 进程内存丢,db 状态停留 → 死循环看不到进度。 启动加一段:扫 status IN (pending,transcribing,summarizing),重置成 pending, 逐个 spawn process_recording 重跑(ASR + LLM idempotent)。 --- apps/notes/src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/notes/src/main.rs b/apps/notes/src/main.rs index 153ac8c..3eabfba 100644 --- a/apps/notes/src/main.rs +++ b/apps/notes/src/main.rs @@ -114,6 +114,43 @@ async fn main() -> std::io::Result<()> { .route("/health", get(|| async { "ok" })) .merge(protected_api); + // 启动时把上次 pod 死前卡在中间状态的 recording 重新喂给 worker。 + // 状态 transcribing/summarizing 是 worker 进程内存的,pod 重启就丢, + // db 还停留在原状态 → 不 resume 永远不会再动。 + { + let stuck: Vec = { + let conn = state.db.lock().unwrap(); + let mut stmt = conn + .prepare( + "SELECT id FROM recordings + WHERE status IN ('pending', 'transcribing', 'summarizing') + ORDER BY id ASC", + ) + .expect("prepare resume query"); + stmt.query_map([], |r| r.get::<_, i64>(0)) + .expect("run resume query") + .collect::, _>>() + .expect("collect resume ids") + }; + if !stuck.is_empty() { + tracing::info!(count = stuck.len(), ids = ?stuck, "resuming stuck recordings"); + for id in stuck { + let s = state.clone(); + tokio::spawn(async move { + // 改回 pending 让 worker 从头跑(idempotent) + { + let conn = s.db.lock().unwrap(); + let _ = conn.execute( + "UPDATE recordings SET status = 'pending', error = NULL WHERE id = ?1", + params![id], + ); + } + process_recording(s, id).await; + }); + } + } + } + let app = cube_core::base(dist).nest("/api", api); cube_core::serve(app, 8080).await }