From f4efbfc95aebcf59385fc7eb00b9d3712ae627a3 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Mon, 27 Oct 2014 13:24:24 -0500 Subject: [PATCH] Working Redis, but need to switch out ZeroMQ. --- awx/api/views.py | 4 +++- awx/main/models/unified_jobs.py | 29 +++++++++++++++++++++++------ awx/main/tasks.py | 3 ++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 499a590518..67007f11a8 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -727,7 +727,9 @@ class ProjectUpdateView(GenericAPIView): return Response({}, status=status.HTTP_400_BAD_REQUEST) else: headers = {'Location': project_update.get_absolute_url()} - return Response(dict(project_update=project_update.id), status=status.HTTP_202_ACCEPTED, headers=headers) + return Response({'project_update': project_update.id}, + headers=headers, + status=status.HTTP_202_ACCEPTED) else: return self.http_method_not_allowed(request, *args, **kwargs) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 189bbc2f8a..97c8720aae 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -674,24 +674,41 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique return True def signal_start(self, **kwargs): - ''' - Notify the task runner system to begin work on this task. - ''' - from awx.main.tasks import notify_task_runner + """Notify the task runner system to begin work on this task.""" + + # Sanity check: If we are running unit tests, then run synchronously. if getattr(settings, 'CELERY_UNIT_TEST', False): return self.start(None, **kwargs) + + # Sanity check: Are we able to start the job? If not, do not attempt + # to do so. if not self.can_start: return False + + # Get any passwords or other data that are prerequisites to running + # the job. needed = self.get_passwords_needed_to_start() opts = dict([(field, kwargs.get(field, '')) for field in needed]) if not all(opts.values()): return False - extra_data = dict([(field, kwargs[field]) for field in kwargs if field not in needed]) + extra_data = dict([(field, kwargs[field]) for field in kwargs + if field not in needed]) self.handle_extra_data(extra_data) + + # Save the pending status, and inform the SocketIO listener. self.update_fields(start_args=json.dumps(kwargs), status='pending') self.socketio_emit_status("pending") + + # Each type of unified job has a different Task class; get the + # appropirate one. task_type = get_type_for_model(self) - # notify_task_runner.delay(dict(task_type=task_type, id=self.id, metadata=kwargs)) + + # Actually tell the task runner to run this task. + from awx.main.tasks import notify_task_runner + notify_task_runner.delay({'id': self.id, 'metadata': kwargs, + 'task_type': task_type}) + + # Done! return True @property diff --git a/awx/main/tasks.py b/awx/main/tasks.py index bd9670b3a0..5b0eea8972 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -112,7 +112,8 @@ def notify_task_runner(metadata_dict): @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))) + print('Executing error task id %s, subtasks: %s' % + (str(self.request.id), str(subtasks))) first_task = None first_task_type = '' first_task_name = ''