def cancel_task(request):
"""Cancel a running task from tasks table
:Example: curl -X GET http://localhost:8082/foglamp/task/cancel/{task_id}
"""
try:
task_id = request.match_info.get('task_id', None)
if not task_id:
raise web.HTTPBadRequest(reason='Task ID is required.')
try:
assert uuid.UUID(task_id)
except ValueError as ex:
raise web.HTTPNotFound(reason="Invalid Task ID {}".format(task_id))
task = await server.Server.scheduler.get_task(task_id)
# Cancel Task
await server.Server.scheduler.cancel_task(uuid.UUID(task_id))
return web.json_response({'id': task_id, 'message': 'Task cancelled successfully'})
except (ValueError, TaskNotFoundError) as ex:
raise web.HTTPNotFound(reason=str(ex))
评论列表
文章目录