MCPcopy
hub / github.com/agent0ai/agent-zero / process

Method process

api/scheduler_task_delete.py:9–53  ·  view source on GitHub ↗

Delete a task from the scheduler by ID

(self, input: Input, request: Request)

Source from the content-addressed store, hash-verified

7
8class SchedulerTaskDelete(ApiHandler):
9 async def process(self, input: Input, request: Request) -> Output:
10 """
11 Delete a task from the scheduler by ID
12 """
13 # Get timezone from input (do not set if not provided, we then rely on poll() to set it)
14 if timezone := input.get("timezone", None):
15 Localization.get().set_timezone(timezone)
16
17 scheduler = TaskScheduler.get()
18 await scheduler.reload()
19
20 # Get task ID from input
21 task_id: str = input.get("task_id", "")
22
23 if not task_id:
24 return {"error": "Missing required field: task_id"}
25
26 # Check if the task exists first
27 task = scheduler.get_task_by_uuid(task_id)
28 if not task:
29 return {"error": f"Task with ID {task_id} not found"}
30
31 context = None
32 if task.context_id:
33 context = self.use_context(task.context_id)
34
35 # If the task is running, update its state to IDLE first
36 if task.state == TaskState.RUNNING:
37 scheduler.cancel_running_task(task_id, terminate_thread=True)
38 if context:
39 context.reset()
40 # Update the state to IDLE so any ongoing processes know to terminate
41 await scheduler.update_task(task_id, state=TaskState.IDLE)
42 # Force a save to ensure the state change is persisted
43 await scheduler.save()
44
45 # This is a dedicated context for the task, so we remove it
46 if context and context.id == task.uuid:
47 AgentContext.remove(context.id)
48 persist_chat.remove_chat(context.id)
49
50 # Remove the task
51 await scheduler.remove_task_by_uuid(task_id)
52
53 return {"success": True, "message": f"Task {task_id} deleted successfully"}

Callers

nothing calls this directly

Calls 11

set_timezoneMethod · 0.80
cancel_running_taskMethod · 0.80
getMethod · 0.45
reloadMethod · 0.45
get_task_by_uuidMethod · 0.45
use_contextMethod · 0.45
resetMethod · 0.45
update_taskMethod · 0.45
saveMethod · 0.45
removeMethod · 0.45
remove_task_by_uuidMethod · 0.45

Tested by

no test coverage detected