修复任务卡死与安能启动失败
- runtime.py: launch_anneng 拉起前清除 NODE_OPTIONS,避免 Electron 因 --use-system-ca 启动即退出(rc=9) - server.py: POST /tasks 在 worker 未就绪时返回 409 拦截误操作;worker 就绪后调用 fail_stale_tasks 实现重启自愈 - state_store.py: 新增 fail_stale_tasks(),将遗留 pending/running 任务标记为 failed
This commit is contained in:
@@ -426,3 +426,16 @@ def list_tasks(limit=20):
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
|
||||
|
||||
def fail_stale_tasks(reason: str = "服务重启,上轮未完成任务,请手动重跑") -> int:
|
||||
"""worker 启动时调用:把遗留的 pending/running 任务标记为 failed,实现重启自愈。
|
||||
返回被清理的任务数量。"""
|
||||
with sqlite3.connect(STATE_DB_PATH) as conn:
|
||||
cur = conn.execute(
|
||||
"UPDATE task_history SET status=?, finished_at=?, error=? "
|
||||
"WHERE status IN (?, ?)",
|
||||
(TASK_FAILED, _now(), reason, TASK_PENDING, TASK_RUNNING),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount
|
||||
|
||||
Reference in New Issue
Block a user