| 123456789101112131415161718192021222324252627 |
- """每次执行的持久化状态;checkpoint 负责续跑,运行表负责展示状态。"""
- from db import db_conn
- def start(run_id: str, session_id: str, user_name: str, kind: str) -> None:
- db_conn.execute(
- "INSERT INTO execution_runs (id, session_id, user_name, kind, status, started_at)"
- " VALUES (?, ?, ?, ?, 'running', ?)",
- (run_id, session_id, user_name, kind, db_conn.fmt_dt()),
- )
- def finish(run_id: str, status: str, error: str = "") -> None:
- db_conn.execute("UPDATE execution_runs SET status = ?, error = ?, finished_at = ? WHERE id = ?",
- (status, error, None if status == "waiting_input" else db_conn.fmt_dt(), run_id))
- def list_runs(session_id: str) -> list[dict]:
- return db_conn.query("SELECT * FROM execution_runs WHERE session_id = ? ORDER BY started_at DESC LIMIT 50",
- (session_id,))
- def recover_interrupted() -> None:
- db_conn.execute("UPDATE execution_runs SET status = 'interrupted', finished_at = ? WHERE status = 'running'",
- (db_conn.fmt_dt(),))
- db_conn.execute("UPDATE schedule_runs SET status = 'interrupted', finished_at = ? WHERE status = 'running'",
- (db_conn.fmt_dt(),))
|