mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 22:05:07 -02:30
Include return code in exception message when task has an error or is canceled.
This commit is contained in:
@@ -386,11 +386,11 @@ class BaseTask(Task):
|
|||||||
child.close(True)
|
child.close(True)
|
||||||
canceled = True
|
canceled = True
|
||||||
if canceled:
|
if canceled:
|
||||||
return 'canceled'
|
return 'canceled', child.exitstatus
|
||||||
elif child.exitstatus == 0:
|
elif child.exitstatus == 0:
|
||||||
return 'successful'
|
return 'successful', child.exitstatus
|
||||||
else:
|
else:
|
||||||
return 'failed'
|
return 'failed', child.exitstatus
|
||||||
|
|
||||||
def post_run_hook(self, instance, **kwargs):
|
def post_run_hook(self, instance, **kwargs):
|
||||||
'''
|
'''
|
||||||
@@ -404,7 +404,7 @@ class BaseTask(Task):
|
|||||||
instance = self.update_model(pk, status='running', celery_task_id=self.request.id)
|
instance = self.update_model(pk, status='running', celery_task_id=self.request.id)
|
||||||
|
|
||||||
instance.socketio_emit_status("running")
|
instance.socketio_emit_status("running")
|
||||||
status, tb = 'error', ''
|
status, rc, tb = 'error', None, ''
|
||||||
output_replacements = []
|
output_replacements = []
|
||||||
try:
|
try:
|
||||||
if instance.cancel_flag:
|
if instance.cancel_flag:
|
||||||
@@ -441,7 +441,7 @@ class BaseTask(Task):
|
|||||||
safe_args = wrap_args_with_proot(safe_args, cwd, **kwargs)
|
safe_args = wrap_args_with_proot(safe_args, cwd, **kwargs)
|
||||||
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
||||||
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
||||||
status = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle)
|
status, rc = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle)
|
||||||
except Exception:
|
except Exception:
|
||||||
if status != 'canceled':
|
if status != 'canceled':
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
@@ -469,9 +469,9 @@ class BaseTask(Task):
|
|||||||
# Raising an exception will mark the job as 'failed' in celery
|
# Raising an exception will mark the job as 'failed' in celery
|
||||||
# and will stop a task chain from continuing to execute
|
# and will stop a task chain from continuing to execute
|
||||||
if status == 'canceled':
|
if status == 'canceled':
|
||||||
raise Exception("Task %s(pk:%s) was canceled" % (str(self.model.__class__), str(pk)))
|
raise Exception("Task %s(pk:%s) was canceled (rc=%s)" % (str(self.model.__class__), str(pk), str(rc)))
|
||||||
else:
|
else:
|
||||||
raise Exception("Task %s(pk:%s) encountered an error" % (str(self.model.__class__), str(pk)))
|
raise Exception("Task %s(pk:%s) encountered an error (rc=%s)" % (str(self.model.__class__), str(pk), str(rc)))
|
||||||
if not hasattr(settings, 'CELERY_UNIT_TEST'):
|
if not hasattr(settings, 'CELERY_UNIT_TEST'):
|
||||||
self.signal_finished(pk)
|
self.signal_finished(pk)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user