mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-17 07:49:01 +00:00
perf: 处理停止任务异常情况
This commit is contained in:
@@ -237,18 +237,21 @@ class JobExecutionViewSet(OrgBulkModelViewSet):
|
|||||||
{'error': _('The task is being created and cannot be interrupted. Please try again later.')},
|
{'error': _('The task is being created and cannot be interrupted. Please try again later.')},
|
||||||
status=400
|
status=400
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
task = AsyncResult(task_id, app=app)
|
||||||
|
inspect = app.control.inspect()
|
||||||
|
|
||||||
task = AsyncResult(task_id, app=app)
|
for worker in inspect.registered().keys():
|
||||||
inspect = app.control.inspect()
|
if not worker.startswith('ansible'):
|
||||||
|
continue
|
||||||
for worker in inspect.registered().keys():
|
if task_id not in [at['id'] for at in inspect.active().get(worker, [])]:
|
||||||
if not worker.startswith('ansible'):
|
# 在队列中未执行使用revoke执行
|
||||||
continue
|
task.revoke(terminate=True)
|
||||||
if task_id not in [at['id'] for at in inspect.active().get(worker, [])]:
|
instance.set_error('Job stop by "revoke task {}"'.format(task_id))
|
||||||
# 在队列中未执行使用revoke执行
|
return Response({'task_id': task_id}, status=200)
|
||||||
task.revoke(terminate=True)
|
except Exception as e:
|
||||||
instance.set_error('Job stop by "revoke task {}"'.format(task_id))
|
instance.set_error(str(e))
|
||||||
return Response({'task_id': task_id}, status=200)
|
return Response({'error': f'Error while stopping the task {task_id}: {e}'}, status=400)
|
||||||
|
|
||||||
instance.stop()
|
instance.stop()
|
||||||
return Response({'task_id': task_id}, status=200)
|
return Response({'task_id': task_id}, status=200)
|
||||||
|
Reference in New Issue
Block a user