Emit just one message type for status change events:

This commit is contained in:
Matthew Jones 2014-04-18 10:54:20 -04:00
parent 6ede456715
commit 92739bc86c
5 changed files with 16 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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']

View File

@ -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'];