scheduler.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:FogLAMP 作者: foglamp 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号