MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / cancel_task

Method cancel_task

core/state.py:289–306  ·  view source on GitHub ↗

Cancel a task (pending or running). Returns True if cancelled, False if already done/failed.

(self, task_id: int)

Source from the content-addressed store, hash-verified

287 self._conn.commit()
288
289 def cancel_task(self, task_id: int) -> bool:
290 """
291 Cancel a task (pending or running).
292 Returns True if cancelled, False if already done/failed.
293 """
294 task = self.get_task(task_id)
295 if not task or task["status"] in ("done", "failed"):
296 return False
297 # Mark cancellation flag so executor can detect it
298 self.set(f"task_cancelled_{task_id}", "1")
299 if task["status"] == "running":
300 with self._lock:
301 self._conn.execute(
302 "UPDATE task_queue SET status = 'failed', result = ?, completed_at = ? WHERE id = ?",
303 ("Cancelled by user", int(time.time()), task_id),
304 )
305 self._conn.commit()
306 return True
307
308 def get_tasks_by_status(self, status: str) -> List[Dict]:
309 """Get all tasks with a given status."""

Callers 1

_handle_cancelMethod · 0.45

Calls 3

get_taskMethod · 0.95
setMethod · 0.95
executeMethod · 0.80

Tested by

no test coverage detected