Fix some bugs and show more error detail on a current task when a previous task fails

This commit is contained in:
Matthew Jones 2014-01-29 15:11:55 -05:00
parent db14daf5e5
commit 6c81d497de
2 changed files with 17 additions and 5 deletions

View File

@ -368,7 +368,7 @@ class Job(CommonTask):
if is_qs.count():
for inventory_source in is_qs:
inventory_update_details = inventory_source.update_signature()
if not inventory_update:
if not inventory_update_details:
# TODO: Set error here
pass
else:
@ -381,7 +381,7 @@ class Job(CommonTask):
run_tasks.append(runnable_tasks[idx]['sig'].set(link_error=handle_work_error.s(subtasks=dependent_tasks)))
run_tasks.append(task_class().si(self.pk, **opts).set(link_error=handle_work_error.s(subtasks=[thisjob])))
print runnable_tasks
res = chain(runnable_tasks)()
res = chain(run_tasks)()
return True
class JobHostSummary(BaseModel):

View File

@ -44,21 +44,33 @@ logger = logging.getLogger('awx.main.tasks')
@task(bind=True)
def handle_work_error(self, task_id, subtasks=None):
print('Executing error task id %s, subtasks: %s' % (str(self.request.id), str(subtasks)))
first_task = None
first_task_type = ''
first_task_name = ''
if subtasks is not None:
for each_task in subtasks:
instance_name = ''
if each_task['type'] == 'project_update':
instance = ProjectUpdate.objects.get(id=each_task['id'])
instance_name = instance.project.name
elif each_task['type'] == 'inventory_update':
instance = InventoryUpdate.objects.get(id=each_task['id'])
elif each_task['type': 'job']:
instance_name = instance.inventory_source.inventory.name
elif each_task['type'] == 'job':
instance = Job.objects.get(id=each_task['id'])
instance_name = instance.job_template.name
else:
# Unknown task type
break
if instance.celery_task_id != instance.celery_task_id:
if first_task is None:
first_task = instance
first_task_type = each_task['type']
first_task_name = instance_name
if instance.celery_task_id != task_id:
instance.status = 'failed'
instance.failed = True
instance.result_traceback = "Previous Task Failed: %s" % str(subtasks)
instance.result_traceback = "Previous Task Failed: %s for %s with celery task id: %s" % \
(first_task_type, first_task_name, task_id)
instance.save()
class BaseTask(Task):