feat(agent): record task run history (#6305)

This commit is contained in:
InfinityPacer
2026-08-13 22:13:36 +08:00
committed by GitHub
parent 4de4fa4391
commit 57e7f86f38
12 changed files with 1016 additions and 128 deletions

View File

@@ -64,6 +64,15 @@ class QueryAgentTasksTool(MoviePilotTool):
next_run_at=scheduler.get_agent_task_next_run(task.id),
timezone=settings.TZ,
)
if task_id:
data["recent_runs"] = [
oper.run_to_dict(run)
for run in oper.list_runs(
task_id=task.id,
user_id=str(self._user_id),
limit=10,
)
]
result.append(data)
return result

View File

@@ -164,11 +164,16 @@ class UpdateAgentTaskTool(MoviePilotTool):
if payload.enabled and task.last_status != "interrupted":
update_payload["last_status"] = "waiting"
oper.update(
updated = oper.update(
task_id=payload.task_id,
payload=update_payload,
user_id=str(self._user_id),
)
if not updated:
current = oper.get(task_id=payload.task_id, user_id=str(self._user_id))
if current and current.last_status == "running":
return {"error": f"Agent 定时任务 {payload.task_id} 正在执行,请稍后再修改"}
return None
scheduler = Scheduler()
next_run_at = scheduler.update_agent_task_job(payload.task_id)
updated_task = oper.get(task_id=payload.task_id, user_id=str(self._user_id))