From 5bfb0f229ce7db94c1ac8bd5fac57f4639e920e1 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 13 Jan 2017 16:34:38 -0500 Subject: [PATCH] graceful handling of null project and inventory in workflow --- awx/main/models/jobs.py | 6 ++++++ awx/main/scheduler/__init__.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 417a4579b8..595289dee7 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -606,6 +606,12 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin): evars.update(extra_vars) self.update_fields(extra_vars=json.dumps(evars)) + def signal_start(self, **kwargs): + # Block cases that would cause the task manager to error + if self.inventory_id is None or self.project_id is None: + return False + return super(Job, self).signal_start(**kwargs) + def display_artifacts(self): ''' Hides artifacts if they are marked as no_log type artifacts. diff --git a/awx/main/scheduler/__init__.py b/awx/main/scheduler/__init__.py index acff2cf8a3..42afbc5337 100644 --- a/awx/main/scheduler/__init__.py +++ b/awx/main/scheduler/__init__.py @@ -10,6 +10,7 @@ from sets import Set from django.conf import settings from django.db import transaction, connection from django.db.utils import DatabaseError +from django.utils.translation import ugettext_lazy as _ # AWX from awx.main.models import * # noqa @@ -123,7 +124,8 @@ class TaskManager(): can_start = job.signal_start(**kv) if not can_start: job.status = 'failed' - job.job_explanation = "Workflow job could not start because it was not in the right state or required manual credentials" + job.job_explanation = _("Job spawned from workflow could not start because it " + "was not in the right state or required manual credentials") job.save(update_fields=['status', 'job_explanation']) connection.on_commit(lambda: job.websocket_emit_status('failed'))