From b0c0176be05f5730961d6ffb396f1c5a6f43e959 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Tue, 18 Jul 2017 16:44:03 -0400 Subject: [PATCH] use task code to cancel dependent project updates --- awx/main/tasks.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 83af9cb9b4..a627dcab60 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -795,11 +795,14 @@ class BaseTask(Task): except Exception: pass + try: + self.post_run_hook(instance, status, **kwargs) + except Exception: + logger.exception('Post run hook of unified job {} errored.'.format(instance.pk)) instance = self.update_model(pk) if instance.cancel_flag: status = 'canceled' - self.post_run_hook(instance, status, **kwargs) instance = self.update_model(pk, status=status, result_traceback=tb, output_replacements=output_replacements, **extra_update_fields) @@ -1423,16 +1426,17 @@ class RunProjectUpdate(BaseTask): # A failed file update does not block other actions logger.error('Encountered error updating project dependent inventory: {}'.format(e)) - # Stop all dependent inventory updates if project update was canceled + # Stop rest of updates if project or inventory update was canceled project_update.refresh_from_db() - if project_update.cancel_flag: - break - # Don't update inventory scm_revision if update was canceled local_inv_update.refresh_from_db() - if local_inv_update.cancel_flag: - continue - inv_src.scm_last_revision = scm_revision - inv_src.save(update_fields=['scm_last_revision']) + if project_update.cancel_flag or local_inv_update.cancel_flag: + if not project_update.cancel_flag: + self.update_model(project_update.pk, cancel_flag=True, job_explanation=_( + 'Dependent inventory update {} was canceled.'.format(local_inv_update.name))) + break + if local_inv_update.status == 'successful': + inv_src.scm_last_revision = scm_revision + inv_src.save(update_fields=['scm_last_revision']) def release_lock(self, instance): try: