From 03249e59f3b6bfc3a1ca8c3628cb9037572baafa Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 25 Mar 2014 15:21:30 -0400 Subject: [PATCH] Fix up job run types so that we aren't auto-starting new jobs. Fix up job dependency generator to call the right new methods for generating inventory and project updates --- awx/main/management/commands/run_task_system.py | 8 ++++---- awx/main/models/inventory.py | 1 + awx/main/models/jobs.py | 5 +++-- awx/main/models/projects.py | 1 + awx/main/models/unified_jobs.py | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/awx/main/management/commands/run_task_system.py b/awx/main/management/commands/run_task_system.py index 5c3b506009..72c5c97515 100644 --- a/awx/main/management/commands/run_task_system.py +++ b/awx/main/management/commands/run_task_system.py @@ -133,9 +133,9 @@ class SimpleDAG(object): def get_tasks(): ''' Fetch all Tower tasks that are relevant to the task management system ''' # TODO: Replace this when we can grab all objects in a sane way - graph_jobs = [j for j in Job.objects.filter(status__in=('new', 'waiting', 'pending', 'running'))] - graph_inventory_updates = [iu for iu in InventoryUpdate.objects.filter(status__in=('new', 'waiting', 'pending', 'running'))] - graph_project_updates = [pu for pu in ProjectUpdate.objects.filter(status__in=('new', 'waiting', 'pending', 'running'))] + graph_jobs = [j for j in Job.objects.filter(status__in=('pending', 'waiting', 'running'))] + graph_inventory_updates = [iu for iu in InventoryUpdate.objects.filter(status__in=('pending', 'waiting', 'running'))] + graph_project_updates = [pu for pu in ProjectUpdate.objects.filter(status__in=('pending', 'waiting', 'running'))] all_actions = sorted(graph_jobs + graph_inventory_updates + graph_project_updates, key=lambda task: task.created) return all_actions @@ -165,7 +165,7 @@ def rebuild_graph(message): return None running_tasks = filter(lambda t: t.status == 'running', all_sorted_tasks) waiting_tasks = filter(lambda t: t.status != 'running', all_sorted_tasks) - new_tasks = filter(lambda t: t.status == 'new', all_sorted_tasks) + new_tasks = filter(lambda t: t.status == 'pending', all_sorted_tasks) # Check running tasks and make sure they are active in celery print("Active celery tasks: " + str(active_tasks)) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index c64cca1eca..73b9df814d 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -740,6 +740,7 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions): self.start_args = json_args self.save() self.start_args = encrypt_field(self, 'start_args') + self.status = 'pending' self.save() # notify_task_runner.delay(dict(task_type="inventory_update", id=self.id, metadata=kwargs)) return True diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 6612b7ff5d..4ad3a9c29d 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -309,11 +309,11 @@ class Job(UnifiedJob, JobOptions): if obj.inventory_source in inventory_sources: inventory_sources_found.append(obj.inventory_source) if not project_found and self.project.scm_update_on_launch: - dependencies.append(self.project.project_updates.create()) + dependencies.append(self.project.create_project_update(launch_type='dependency')) if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner for source in inventory_sources: if not source in inventory_sources_found: - dependencies.append(source.inventory_updates.create()) + dependencies.append(source.create_inventory_update(launch_type='dependency')) return dependencies def signal_start(self, **kwargs): @@ -331,6 +331,7 @@ class Job(UnifiedJob, JobOptions): self.start_args = json_args self.save() self.start_args = encrypt_field(self, 'start_args') + self.status = 'pending' self.save() # notify_task_runner.delay(dict(task_type="ansible_playbook", id=self.id)) return True diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index b5a3486f84..30464e29a1 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -358,6 +358,7 @@ class ProjectUpdate(UnifiedJob, ProjectOptions): self.start_args = json_args self.save() self.start_args = encrypt_field(self, 'start_args') + self.status = 'pending' self.save() # notify_task_runner.delay(dict(task_type="project_update", id=self.id, metadata=kwargs)) return True diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 7abd99b870..434f98da23 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -456,7 +456,7 @@ class UnifiedJob(PolymorphicModel, CommonModelNameNotUnique): def start(self, error_callback, **kwargs): task_class = self._get_task_class() - if not self.can_start: # self.status == 'waiting': # FIXME: Why did this not include "new"? + if not self.can_start: return False needed = self._get_passwords_needed_to_start() try: