From e72728b38c09aea504907c8bd90b56449e7b9d18 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 10 Jun 2014 15:58:11 -0400 Subject: [PATCH] Add schedule based socket.io events for AC-1333 --- awx/main/management/commands/run_socketio_service.py | 8 +++++++- awx/main/models/schedules.py | 3 ++- awx/main/tasks.py | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/awx/main/management/commands/run_socketio_service.py b/awx/main/management/commands/run_socketio_service.py index 1bf4b0d718..0bb603625b 100644 --- a/awx/main/management/commands/run_socketio_service.py +++ b/awx/main/management/commands/run_socketio_service.py @@ -49,6 +49,11 @@ class JobEventNamespace(BaseNamespace): def recv_connect(self): print("Received client connect for job event namespace from %s" % str(self.environ['REMOTE_ADDR'])) +class ScheduleNamespace(BaseNamespace): + + def recv_connect(self): + print("Received client connect for schedule namespace from %s" % str(self.environ['REMOTE_ADDR'])) + class TowerSocket(object): def __call__(self, environ, start_response): @@ -57,7 +62,8 @@ class TowerSocket(object): if path.startswith('socket.io'): socketio_manage(environ, {'/socket.io/test': TestNamespace, '/socket.io/jobs': JobNamespace, - '/socket.io/job_events': JobEventNamespace}) + '/socket.io/job_events': JobEventNamespace, + '/socket.io/schedules': ScheduleNamespace}) else: start_response('404 Not Found', []) return ['Tower version %s' % awx.__version__] diff --git a/awx/main/models/schedules.py b/awx/main/models/schedules.py index 97df9d0e4f..d6619648db 100644 --- a/awx/main/models/schedules.py +++ b/awx/main/models/schedules.py @@ -13,7 +13,7 @@ from django.utils.timezone import now, make_aware, get_default_timezone # AWX from awx.main.models.base import * -from awx.main.utils import ignore_inventory_computed_fields +from awx.main.utils import ignore_inventory_computed_fields, emit_websocket_notification from django.core.urlresolvers import reverse logger = logging.getLogger('awx.main.models.schedule') @@ -105,6 +105,7 @@ class Schedule(CommonModel): self.dtend = make_aware(datetime.datetime.strptime(until_date, "%Y%m%dT%H%M%SZ"), get_default_timezone()) if 'count' in self.rrule.lower(): self.dtend = future_rs[-1] + emit_websocket_notification('/socket.io/schedules', 'schedule_change', dict(id=self.id)) with ignore_inventory_computed_fields(): self.unified_job_template.update_computed_fields() diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 8ef24acf7f..3a0faf0fe8 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -37,7 +37,7 @@ from django.utils.timezone import now # AWX from awx.main.models import * # Job, JobEvent, ProjectUpdate, InventoryUpdate, Schedule, UnifiedJobTemplate -from awx.main.utils import get_ansible_version, decrypt_field, update_scm_url, ignore_inventory_computed_fields +from awx.main.utils import get_ansible_version, decrypt_field, update_scm_url, ignore_inventory_computed_fields, emit_websocket_notification __all__ = ['RunJob', 'RunProjectUpdate', 'RunInventoryUpdate', 'handle_work_error', 'update_inventory_computed_fields'] @@ -96,6 +96,7 @@ def tower_periodic_scheduler(self): 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']) new_unified_job.socketio_emit_status("failed") + emit_websocket_notification('/socket.io/schedules', 'schedule_change', dict(id=schedule.id)) @task() def notify_task_runner(metadata_dict):