detect celery failure

This commit is contained in:
yangdsh 2020-02-24 18:40:52 +00:00 committed by Dana Van Aken
parent 2293fac4d3
commit 27a275e21e
1 changed files with 15 additions and 16 deletions

View File

@ -1178,23 +1178,22 @@ def give_result(request, upload_code): # pylint: disable=unused-argument
response = dict(celery_status='', result_id=latest_result.pk, message='', errors=[]) response = dict(celery_status='', result_id=latest_result.pk, message='', errors=[])
if group_res.ready(): if group_res.failed():
if group_res.failed(): errors = [t.traceback for t in task_list if t.traceback]
errors = [t.traceback for t in task_list if t.traceback] if errors:
if errors: LOG.warning('\n\n'.join(errors))
LOG.warning('\n\n'.join(errors)) response.update(
response.update( celery_status='FAILURE', errors=errors,
celery_status='FAILURE', errors=errors, message='Celery failed to get the next configuration')
message='Celery failed to get the next configuration') status_code = 400
status_code = 400
else: elif group_res.ready():
assert group_res.successful() assert group_res.successful()
next_config = JSONUtil.loads(next_config) next_config = JSONUtil.loads(next_config)
response.update( response.update(
next_config, celery_status='SUCCESS', next_config, celery_status='SUCCESS',
message='Celery successfully recommended the next configuration') message='Celery successfully recommended the next configuration')
status_code = 200 status_code = 200
else: # One or more tasks are still waiting to execute else: # One or more tasks are still waiting to execute
celery_status = 'PENDING' celery_status = 'PENDING'