From 51a6194b8dc1e696204c9988d444606d19e3d22c Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 24 Feb 2020 11:08:39 -0500 Subject: [PATCH] Removes logic performing GET requests on `api/v2/templates` whenever a job status update message comes across the websocket. We now use data exclusively from the websocket to update the UI. --- .../templates/templatesList.controller.js | 61 +++++++++---------- .../smart-status/smart-status.controller.js | 4 +- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/awx/ui/client/features/templates/templatesList.controller.js b/awx/ui/client/features/templates/templatesList.controller.js index 8c95aa745a..8481135d1e 100644 --- a/awx/ui/client/features/templates/templatesList.controller.js +++ b/awx/ui/client/features/templates/templatesList.controller.js @@ -24,7 +24,6 @@ function ListTemplatesController( qs, GetBasePath, ngToast, - $timeout ) { const vm = this || {}; const [jobTemplate, workflowTemplate] = resolvedModels; @@ -32,10 +31,6 @@ function ListTemplatesController( const choices = workflowTemplate.options('actions.GET.type.choices') .concat(jobTemplate.options('actions.GET.type.choices')); - let launchModalOpen = false; - let refreshAfterLaunchClose = false; - let pendingRefresh = false; - let refreshTimerRunning = false; let paginateQuerySet = {}; vm.strings = strings; @@ -120,25 +115,35 @@ function ListTemplatesController( setToolbarSort(); }, true); - $scope.$on(`ws-jobs`, () => { - if (!launchModalOpen) { - if (!refreshTimerRunning) { - refreshTemplates(); - } else { - pendingRefresh = true; - } - } else { - refreshAfterLaunchClose = true; - } - }); + $scope.$on(`ws-jobs`, (e, msg) => { + if (msg.unified_job_template_id && vm.templates) { + const template = vm.templates.find((t) => t.id === msg.unified_job_template_id); + if (template) { + if (msg.status === 'pending') { + // This is a new job - add it to the front of the + // recent_jobs array + if (template.summary_fields.recent_jobs.length === 10) { + template.summary_fields.recent_jobs.pop(); + } - $scope.$on('launchModalOpen', (evt, isOpen) => { - evt.stopPropagation(); - if (!isOpen && refreshAfterLaunchClose) { - refreshAfterLaunchClose = false; - refreshTemplates(); + template.summary_fields.recent_jobs.unshift({ + id: msg.unified_job_id, + status: msg.status, + type: msg.type + }); + } else { + // This is an update to an existing job. Check to see + // if we have it in our array of recent_jobs + for (let i=0; i { @@ -265,15 +270,6 @@ function ListTemplatesController( vm.templates = vm.dataset.results; }) .finally(() => Wait('stop')); - pendingRefresh = false; - refreshTimerRunning = true; - $timeout(() => { - if (pendingRefresh) { - refreshTemplates(); - } else { - refreshTimerRunning = false; - } - }, 5000); } function createErrorHandler(path, action) { @@ -483,8 +479,7 @@ ListTemplatesController.$inject = [ 'Wait', 'QuerySet', 'GetBasePath', - 'ngToast', - '$timeout' + 'ngToast' ]; export default ListTemplatesController; diff --git a/awx/ui/client/src/smart-status/smart-status.controller.js b/awx/ui/client/src/smart-status/smart-status.controller.js index a974e31ee3..1e07342d58 100644 --- a/awx/ui/client/src/smart-status/smart-status.controller.js +++ b/awx/ui/client/src/smart-status/smart-status.controller.js @@ -90,9 +90,9 @@ export default ['$scope', '$filter', 'i18n', 'JobsStrings', $scope.sparkArray = sparkData; $scope.placeholders = new Array(10 - sparkData.length); } - $scope.$watchCollection('jobs', function(){ + $scope.$watch('jobs', function(){ init(); - }); + }, true); }];