From 3ade961e92a649bbc3875fe19dd907e41e2d3799 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 10 Oct 2016 11:22:56 -0700 Subject: [PATCH] Rebase of devel (w/ channels) + socket rework for new job details Replacing old socket.io receiver w/ new websocket receivers --- .../client/src/job-detail/job-detail.route.js | 9 ++++++ .../src/job-results/job-results.controller.js | 31 +++++++++++-------- .../src/job-results/job-results.route.js | 25 ++++----------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/awx/ui/client/src/job-detail/job-detail.route.js b/awx/ui/client/src/job-detail/job-detail.route.js index dd8a7ff5ba..9f288dac34 100644 --- a/awx/ui/client/src/job-detail/job-detail.route.js +++ b/awx/ui/client/src/job-detail/job-detail.route.js @@ -1,3 +1,4 @@ +<<<<<<< 4cf6a946a1aa14b7d64a8e1e8dabecfd3d056f27 //<<<<<<< bc59236851902d7c768aa26abdb7dc9c9dc27a5a /************************************************* * Copyright (c) 2016 Ansible, Inc. @@ -46,6 +47,8 @@ // controller: 'JobDetailController' // }; //======= +======= +>>>>>>> Rebase of devel (w/ channels) + socket rework for new job details // /************************************************* // * Copyright (c) 2016 Ansible, Inc. // * @@ -61,6 +64,12 @@ // parent: 'jobs', // label: "{{ job.id }} - {{ job.name }}" // }, +// socket: { +// "groups":{ +// "jobs": ["status_changed", "summary"], +// "job_events": [] +// } +// }, // resolve: { // jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { // if (!$rootScope.event_socket) { diff --git a/awx/ui/client/src/job-results/job-results.controller.js b/awx/ui/client/src/job-results/job-results.controller.js index 1d845a697b..20fd0686b4 100644 --- a/awx/ui/client/src/job-results/job-results.controller.js +++ b/awx/ui/client/src/job-results/job-results.controller.js @@ -76,13 +76,6 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'count', '$scope', 'Pa $scope.hostCount = getTotalHostCount(count.val); $scope.countFinished = count.countFinished; - // Process incoming job status changes - $rootScope.$on('JobStatusChange-jobDetails', function(e, data) { - if (parseInt(data.unified_job_id, 10) === parseInt($scope.job.id,10)) { - $scope.job.status = data.status; - } - }); - // EVENT STUFF BELOW // just putting the event queue on scope so it can be inspected in the @@ -150,14 +143,26 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'count', '$scope', 'Pa }; getEvents($scope.job.related.job_events); - // PUSH! process incoming job events - $rootScope.event_socket.on("job_events-" + $scope.job.id, function(data) { + // Processing of job_events messages from the websocket + $scope.$on(`ws-job_events-${$scope.job.id}`, function(e, data) { processEvent(data); }); - // STOP! stop listening to job events - $scope.$on('$destroy', function() { - $rootScope.event_socket.removeAllListeners("job_events-" + - $scope.job.id); + // Processing of job-status messages from the websocket + $scope.$on(`ws-jobs`, function(e, data) { + if (parseInt(data.unified_job_id, 10) === parseInt($scope.job.id,10)) { + $scope.job.status = data.status; + } }); + + // The code below was used in the old job detail controller, + // and is for processing the 'Job Summary' event that is delivered + // for a completed job. Not sure if we have an equivalent function + // at this point. TODO: write function to handle Job Summary + // scope.$on('ws-jobs-summary', function() { + // // the job host summary should now be available from the API + // $log.debug('Trigging reload of job_host_summaries'); + // scope.$emit('InitialLoadComplete'); + // }); + }]; diff --git a/awx/ui/client/src/job-results/job-results.route.js b/awx/ui/client/src/job-results/job-results.route.js index 8151546468..902f9f3203 100644 --- a/awx/ui/client/src/job-results/job-results.route.js +++ b/awx/ui/client/src/job-results/job-results.route.js @@ -15,6 +15,12 @@ export default { parent: 'jobs', label: '{{ job.id }} - {{ job.name }}' }, + socket: { + "groups":{ + "jobs": ["status_changed", "summary"], + "job_events": [] + } + }, resolve: { // the GET for the particular job jobData: ['Rest', 'GetBasePath', '$stateParams', '$q', '$state', 'Alert', function(Rest, GetBasePath, $stateParams, $q, $state, Alert) { @@ -122,25 +128,6 @@ export default { }); return val.promise; }], - // This gives us access to the job events socket so we can start - // listening for updates we need to make for the ui as data comes in - // - // TODO: we could probably make this better by not initing - // job_events for completed jobs - jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { - if (!$rootScope.event_socket) { - $rootScope.event_socket = Socket({ - scope: $rootScope, - endpoint: "job_events" - }); - $rootScope.event_socket.init(); - // returns should really be providing $rootScope.event_socket - // otherwise, we have to inject the entire $rootScope into the controller - return true; - } else { - return true; - } - }], // This clears out the event queue, otherwise it'd be full of events // for previous job results the user had navigated to eventQueueInit: ['eventQueue', function(eventQueue) {