This commit is contained in:
Timothy Jaeryang Baek 2025-07-12 03:00:40 +04:00
parent 627f680659
commit 955c2e2570

View file

@ -153,7 +153,7 @@ async def stop_task(redis, task_id: str):
# Optionally check if task_id still in Redis a few moments later for feedback? # Optionally check if task_id still in Redis a few moments later for feedback?
return {"status": True, "message": f"Stop signal sent for {task_id}"} return {"status": True, "message": f"Stop signal sent for {task_id}"}
task = tasks.get(task_id) task = tasks.pop(task_id)
if not task: if not task:
raise ValueError(f"Task with ID {task_id} not found.") raise ValueError(f"Task with ID {task_id} not found.")
@ -162,7 +162,6 @@ async def stop_task(redis, task_id: str):
await task # Wait for the task to handle the cancellation await task # Wait for the task to handle the cancellation
except asyncio.CancelledError: except asyncio.CancelledError:
# Task successfully canceled # Task successfully canceled
tasks.pop(task_id, None) # Remove it from the dictionary
return {"status": True, "message": f"Task {task_id} successfully stopped."} return {"status": True, "message": f"Task {task_id} successfully stopped."}
return {"status": False, "message": f"Failed to stop task {task_id}."} return {"status": False, "message": f"Failed to stop task {task_id}."}