From d6c6113112c84379a308ee62ef132b1e615f7b34 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Fri, 2 Oct 2026 22:08:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(automation):=20=E8=A2=AB=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E6=89=93=E6=96=AD=E7=9A=84=E8=BD=AE=E6=AC=A1=E8=AE=B0=E4=B8=BA?= =?UTF-8?q?=20interrupted=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=B7=B7=E8=BF=9B=20f?= =?UTF-8?q?ailed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 部署重建容器会打断正在跑的作业,那轮永远写不回结果,由启动时的 cleanup_orphan_runs 收尾。之前收尾成 failed,于是页面上一片红 —— 但这并不是 作业本身的失败:账号侧的 CK 一个没丢(旧 Cookie 已保留),被中断的账号也会按 退避自动重试。混在 failed 里会掩盖真正的失败(如 SQL 语法错误)。 改为独立状态 interrupted,前端用中性灰显示「被中断」,与红色的「失败」区分开。 --- tests/test_automation_ck_health.py | 2 +- web/backend/services/automation/scheduler.py | 5 ++++- web/frontend/src/pages/AutomationPage.tsx | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_automation_ck_health.py b/tests/test_automation_ck_health.py index 2241a2c..6a467ac 100644 --- a/tests/test_automation_ck_health.py +++ b/tests/test_automation_ck_health.py @@ -617,7 +617,7 @@ class TestOrphanRunCleanup(_Base): self.session.refresh(stale) self.session.refresh(done) assert cleaned == 1 - assert stale.status == "failed" + assert stale.status == "interrupted" assert stale.finished_at is not None assert stale.message == "服务重启中断" assert done.status == "success" # 已完成的不受影响 diff --git a/web/backend/services/automation/scheduler.py b/web/backend/services/automation/scheduler.py index 05174ea..e32b64c 100644 --- a/web/backend/services/automation/scheduler.py +++ b/web/backend/services/automation/scheduler.py @@ -140,7 +140,10 @@ def cleanup_orphan_runs(db: Session, message: str = "服务重启中断") -> int """ orphans = db.query(AutomationRun).filter(AutomationRun.status == "running").all() for run in orphans: - run.status = "failed" + # 用 interrupted 而不是 failed:这不是作业本身的失败(账号侧 CK 没丢、 + # 被中断的也会按退避重试),只是进程没了导致那轮没跑完。混进 failed + # 会让页面一片红,掩盖真正的失败。 + run.status = "interrupted" run.finished_at = datetime.now(UTC) run.message = message if orphans: diff --git a/web/frontend/src/pages/AutomationPage.tsx b/web/frontend/src/pages/AutomationPage.tsx index b5eba65..95100ea 100644 --- a/web/frontend/src/pages/AutomationPage.tsx +++ b/web/frontend/src/pages/AutomationPage.tsx @@ -31,6 +31,9 @@ import { formatTime } from "../utils/time"; const STATUS_TAG: Record = { success: { color: "green", text: "成功" }, failed: { color: "red", text: "失败" }, + // 被部署/重启打断:不是作业本身的失败(CK 没丢,会自动重试), + // 用中性色,避免和真失败混在一起。 + interrupted: { color: "default", text: "被中断" }, running: { color: "blue", text: "执行中" }, skipped: { color: "default", text: "已跳过" }, };