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.

This commit is contained in:
mabashian
2020-02-24 11:08:39 -05:00
committed by Rebeccah
parent e75f7b0beb
commit 51a6194b8d
2 changed files with 30 additions and 35 deletions

View File

@@ -24,7 +24,6 @@ function ListTemplatesController(
qs, qs,
GetBasePath, GetBasePath,
ngToast, ngToast,
$timeout
) { ) {
const vm = this || {}; const vm = this || {};
const [jobTemplate, workflowTemplate] = resolvedModels; const [jobTemplate, workflowTemplate] = resolvedModels;
@@ -32,10 +31,6 @@ function ListTemplatesController(
const choices = workflowTemplate.options('actions.GET.type.choices') const choices = workflowTemplate.options('actions.GET.type.choices')
.concat(jobTemplate.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 = {}; let paginateQuerySet = {};
vm.strings = strings; vm.strings = strings;
@@ -120,25 +115,35 @@ function ListTemplatesController(
setToolbarSort(); setToolbarSort();
}, true); }, true);
$scope.$on(`ws-jobs`, () => { $scope.$on(`ws-jobs`, (e, msg) => {
if (!launchModalOpen) { if (msg.unified_job_template_id && vm.templates) {
if (!refreshTimerRunning) { const template = vm.templates.find((t) => t.id === msg.unified_job_template_id);
refreshTemplates(); if (template) {
} else { if (msg.status === 'pending') {
pendingRefresh = true; // This is a new job - add it to the front of the
} // recent_jobs array
} else { if (template.summary_fields.recent_jobs.length === 10) {
refreshAfterLaunchClose = true; template.summary_fields.recent_jobs.pop();
} }
});
$scope.$on('launchModalOpen', (evt, isOpen) => { template.summary_fields.recent_jobs.unshift({
evt.stopPropagation(); id: msg.unified_job_id,
if (!isOpen && refreshAfterLaunchClose) { status: msg.status,
refreshAfterLaunchClose = false; type: msg.type
refreshTemplates(); });
} 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<template.summary_fields.recent_jobs.length; i++) {
const recentJob = template.summary_fields.recent_jobs[i];
if (recentJob.id === msg.unified_job_id) {
recentJob.status = msg.status;
break;
}
};
}
}
} }
launchModalOpen = isOpen;
}); });
vm.isInvalid = (template) => { vm.isInvalid = (template) => {
@@ -265,15 +270,6 @@ function ListTemplatesController(
vm.templates = vm.dataset.results; vm.templates = vm.dataset.results;
}) })
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
pendingRefresh = false;
refreshTimerRunning = true;
$timeout(() => {
if (pendingRefresh) {
refreshTemplates();
} else {
refreshTimerRunning = false;
}
}, 5000);
} }
function createErrorHandler(path, action) { function createErrorHandler(path, action) {
@@ -483,8 +479,7 @@ ListTemplatesController.$inject = [
'Wait', 'Wait',
'QuerySet', 'QuerySet',
'GetBasePath', 'GetBasePath',
'ngToast', 'ngToast'
'$timeout'
]; ];
export default ListTemplatesController; export default ListTemplatesController;

View File

@@ -90,9 +90,9 @@ export default ['$scope', '$filter', 'i18n', 'JobsStrings',
$scope.sparkArray = sparkData; $scope.sparkArray = sparkData;
$scope.placeholders = new Array(10 - sparkData.length); $scope.placeholders = new Array(10 - sparkData.length);
} }
$scope.$watchCollection('jobs', function(){ $scope.$watch('jobs', function(){
init(); init();
}); }, true);
}]; }];