fix: 更正接口命名
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user