From 92739bc86cf0376204edff1cf7e30c8694081c14 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 18 Apr 2014 10:54:20 -0400 Subject: [PATCH] Emit just one message type for status change events: --- awx/main/management/commands/run_task_system.py | 2 +- awx/main/models/unified_jobs.py | 5 +++-- awx/main/tasks.py | 7 ++++--- awx/main/utils.py | 3 +++ awx/ui/static/js/controllers/Sockets.js | 6 +++++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/awx/main/management/commands/run_task_system.py b/awx/main/management/commands/run_task_system.py index 4859a23d9e..1b2c776b3c 100644 --- a/awx/main/management/commands/run_task_system.py +++ b/awx/main/management/commands/run_task_system.py @@ -175,7 +175,7 @@ def rebuild_graph(message): task.status = 'failed' task.job_explanation += "Task was marked as running in Tower but was not present in Celery so it has been marked as failed" task.save() - emit_websocket_notification('/socket.io/jobs', 'job_canceled', dict(unified_job_id=task.id)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=task.id)) running_tasks.pop(running_tasks.index(task)) print("Task %s appears orphaned... marking as failed" % task) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index fb941369ef..58143eb48a 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -583,7 +583,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique if not all(opts.values()): return False self.update_fields(start_args=json.dumps(kwargs), status='pending') - emit_websocket_notification('/socket.io/jobs', 'job_started', dict(unified_job_id=self.id)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=self.id)) task_type = get_type_for_model(self) # notify_task_runner.delay(dict(task_type=task_type, id=self.id, metadata=kwargs)) return True @@ -623,6 +623,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique instance.job_explanation = 'Forced cancel' update_fields.append('job_explanation') instance.save(update_fields=update_fields) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=instance.id)) except: # FIXME: Log this exception! if settings.DEBUG: raise @@ -632,7 +633,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique if not self.cancel_flag: self.cancel_flag = True self.save(update_fields=['cancel_flag']) - emit_websocket_notification('/socket.io/jobs', 'job_canceled', dict(unified_job_id=self.id)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=self.id)) if settings.BROKER_URL.startswith('amqp://'): self._force_cancel() return self.cancel_flag diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 3c315f02cd..5dd9096464 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -84,6 +84,7 @@ def tower_periodic_scheduler(self): new_unified_job.status = 'failed' new_unified_job.job_explanation = "Scheduled job could not start because it was not in the right state or required manual credentials" new_unified_job.save(update_fields=['job_status', 'job_explanation']) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=new_unified_job.id)) @task() def notify_task_runner(metadata_dict): @@ -123,7 +124,7 @@ def handle_work_error(self, task_id, subtasks=None): instance.job_explanation = "Previous Task Failed: %s for %s with celery task id: %s" % \ (first_task_type, first_task_name, task_id) instance.save() - emit_websocket_notification('/socket.io/jobs', 'job_error', dict(unified_job_id=instance.id)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=instance.id)) class BaseTask(Task): @@ -334,7 +335,7 @@ class BaseTask(Task): ''' Run the job/task and capture its output. ''' - emit_websocket_notification('/socket.io/jobs', 'job_running', dict(unified_job_id=pk)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=pk)) instance = self.update_model(pk, status='running', celery_task_id=self.request.id) status, tb = 'error', '' output_replacements = [] @@ -383,7 +384,7 @@ class BaseTask(Task): instance = self.update_model(pk, status=status, result_traceback=tb, output_replacements=output_replacements) self.post_run_hook(instance, **kwargs) - emit_websocket_notification('/socket.io/jobs', 'job_finished', dict(unified_job_id=pk)) + emit_websocket_notification('/socket.io/jobs', 'status_changed', dict(unified_job_id=pk)) if status != 'successful' and not hasattr(settings, 'CELERY_UNIT_TEST'): # Raising an exception will mark the job as 'failed' in celery # and will stop a task chain from continuing to execute diff --git a/awx/main/utils.py b/awx/main/utils.py index c9d185b30b..a9a582b03a 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -19,6 +19,9 @@ from Crypto.Cipher import AES # ZeroMQ import zmq +# Django +from django.conf import settings + __all__ = ['get_object_or_400', 'get_object_or_403', 'camelcase_to_underscore', 'get_ansible_version', 'get_awx_version', 'update_scm_url', 'get_type_for_model', 'get_model_for_type'] diff --git a/awx/ui/static/js/controllers/Sockets.js b/awx/ui/static/js/controllers/Sockets.js index e3a5d7ccbf..f5d0a7f299 100644 --- a/awx/ui/static/js/controllers/Sockets.js +++ b/awx/ui/static/js/controllers/Sockets.js @@ -41,7 +41,7 @@ function SocketsController ($scope, $compile, ClearScope, Socket) { e = angular.element(document.getElementById('job-events-container')); e.append(html); $compile(e)(job_events_scope); - + test_socket.init(); jobs_socket.init(); job_events_socket.init(); @@ -51,6 +51,10 @@ function SocketsController ($scope, $compile, ClearScope, Socket) { test_socket.on('test', function(data) { test_scope.messages.push(data); }); + + jobs_socket.on("status_changed", function(data) { + jobs_scope.messages.push(data); + }); } SocketsController.$inject = [ '$scope', '$compile', 'ClearScope', 'Socket'];