Some checks failed
CI / test (push) Failing after 59s
评测任务是进程内 asyncio 任务,服务重启会中断执行且状态永远停在 running。启动时将遗留的 running/pending 运行标记为 failed(summary 写入 interrupted 错误),清理为尽力而为,不阻断启动。另将仪表盘最近 评测记录的触发方式与版本号标签位置对调。
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
"""Startup cleanup of orphan runs (interrupted by server restart)."""
|
|
|
|
from agenteval.models import EvalRun, RunStatus
|
|
from agenteval.storage.repository import RunRepository
|
|
|
|
|
|
def _make_run(session, status: RunStatus) -> str:
|
|
run = RunRepository(session).create(EvalRun(
|
|
target_id="t-1", scenario_id="s-1", status=status,
|
|
))
|
|
return run.id
|
|
|
|
|
|
def test_mark_orphans_failed(db_session):
|
|
repo = RunRepository(db_session)
|
|
running_id = _make_run(db_session, RunStatus.RUNNING)
|
|
pending_id = _make_run(db_session, RunStatus.PENDING)
|
|
completed_id = _make_run(db_session, RunStatus.COMPLETED)
|
|
failed_id = _make_run(db_session, RunStatus.FAILED)
|
|
|
|
count = repo.mark_orphans_failed()
|
|
|
|
assert count == 2
|
|
for rid in (running_id, pending_id):
|
|
run = repo.get(rid)
|
|
assert run.status == RunStatus.FAILED
|
|
assert run.summary["error"]["code"] == "interrupted"
|
|
assert run.completed_at is not None
|
|
# 已完结的运行不受影响
|
|
assert repo.get(completed_id).status == RunStatus.COMPLETED
|
|
assert repo.get(failed_id).status == RunStatus.FAILED
|
|
assert repo.get(completed_id).summary is None
|
|
|
|
|
|
def test_mark_orphans_failed_noop_when_clean(db_session):
|
|
repo = RunRepository(db_session)
|
|
_make_run(db_session, RunStatus.COMPLETED)
|
|
assert repo.mark_orphans_failed() == 0
|