mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-22 08:43:37 +08:00
feat(agent): record task run history (#6305)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user