From 135555e3ea4c0cf408b6bdbe46bde61eb0568f66 Mon Sep 17 00:00:00 2001 From: DLmaster361 Date: Sat, 9 Aug 2025 01:55:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=AD=A3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/dispatch.py | 6 +++--- app/core/task_manager.py | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/api/dispatch.py b/app/api/dispatch.py index 3a9fa98..0fbccf0 100644 --- a/app/api/dispatch.py +++ b/app/api/dispatch.py @@ -32,7 +32,7 @@ router = APIRouter(prefix="/api/dispatch", tags=["任务调度"]) @router.post( "/start", summary="添加任务", response_model=TaskCreateOut, status_code=200 ) -async def add_plan(task: TaskCreateIn = Body(...)) -> TaskCreateOut: +async def add_task(task: TaskCreateIn = Body(...)) -> TaskCreateOut: try: task_id = await TaskManager.add_task(task.mode, task.taskId) @@ -42,10 +42,10 @@ async def add_plan(task: TaskCreateIn = Body(...)) -> TaskCreateOut: @router.post("/stop", summary="中止任务", response_model=OutBase, status_code=200) -async def stop_plan(plan: DispatchIn = Body(...)) -> OutBase: +async def stop_task(task: DispatchIn = Body(...)) -> OutBase: try: - await Config.del_plan(plan.taskId) + await TaskManager.stop_task(task.taskId) except Exception as e: return OutBase(code=500, status="error", message=str(e)) return OutBase() diff --git a/app/core/task_manager.py b/app/core/task_manager.py index cf734b0..d58eaa0 100644 --- a/app/core/task_manager.py +++ b/app/core/task_manager.py @@ -210,7 +210,7 @@ class _TaskManager: lambda t: asyncio.create_task(task_item.final_task(t)) ) - async def stop_task(self, task_id: uuid.UUID) -> None: + async def stop_task(self, task_id: str) -> None: """ 中止任务 @@ -219,10 +219,12 @@ class _TaskManager: logger.info(f"中止任务:{task_id}") - if task_id not in self.task_dict: - raise ValueError(f"The task {task_id} is not running.") + uid = uuid.UUID(task_id) - self.task_dict[task_id].cancel() + if uid not in self.task_dict: + raise ValueError(f"The task {uid} is not running.") + + self.task_dict[uid].cancel() async def remove_task( self, task: asyncio.Task, mode: str, task_id: uuid.UUID