1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Job detail page refactor

Reverting attempt to use _.throttle and _.defer. They assume we actually want to process every event. We need to stop all processing if the job has finished.
This commit is contained in:
Chris Houseknecht 2014-06-19 02:21:13 -04:00 committed by Luke Sneeringer
parent cb44949a1d
commit 3a6fe9ee4a
2 changed files with 40 additions and 48 deletions

View File

@ -9,7 +9,7 @@
function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest,
ProcessErrors, ProcessEventQueue, SelectPlay, SelectTask, Socket, GetElapsed, FilterAllByHostName, DrawGraph, LoadHostSummary, ReloadHostSummaryList,
JobIsFinished, SetTaskStyles, DigestEvent) {
JobIsFinished, SetTaskStyles) {
ClearScope();
@ -19,8 +19,7 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log,
api_complete = false,
refresh_count = 0,
lastEventId = 0,
queue = [],
processEvent;
queue = [];
scope.plays = [];
scope.playsMap = {};
@ -67,42 +66,27 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log,
event_socket.init();
processEvent = _.throttle(function() {
var event;
if (queue.length > 0) {
event = queue.pop();
$log.debug('processing event: ' + event.id);
DigestEvent({
scope: scope,
event: event
});
}
}, 200);
event_socket.on("job_events-" + job_id, function(data) {
data.event = data.event_name;
if (api_complete && data.id > lastEventId) {
$log.debug('received event: ' + data.id);
queue.unshift(data);
processEvent();
if (queue.length < 20) {
queue.unshift(data);
}
else {
api_complete = false; // stop more events from hitting the queue
window.clearInterval($rootScope.jobDetailInterval);
$log.debug('queue halted. reloading...');
setTimeout(function() {
$log.debug('reload');
scope.haltEventQueue = true;
queue = [];
scope.$emit('LoadJob');
}, 300);
}
}
//if (queue.length < 20) {
// queue.unshift(data);
//}
//*else {
// api_complete = false; // stop more events from hitting the queue
// $log.debug('queue halted. reloading in 1.');
// setTimeout(function() {
// $log.debug('reloading');
// scope.haltEventQueue = true;
// queue = [];
// scope.$emit('LoadJob');
// }, 1000);
// }
//}
});
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
@ -121,6 +105,7 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log,
}
});
if (scope.removeAPIComplete) {
scope.removeAPIComplete();
}
@ -167,10 +152,10 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log,
DrawGraph({ scope: scope, resize: true });
}
//ProcessEventQueue({
// scope: scope,
// eventQueue: queue
//});
ProcessEventQueue({
scope: scope,
eventQueue: queue
});
});
@ -984,5 +969,5 @@ function JobDetailController ($rootScope, $scope, $compile, $routeParams, $log,
JobDetailController.$inject = [ '$rootScope', '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath',
'Wait', 'Rest', 'ProcessErrors', 'ProcessEventQueue', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'FilterAllByHostName', 'DrawGraph',
'LoadHostSummary', 'ReloadHostSummaryList', 'JobIsFinished', 'SetTaskStyles', 'DigestEvent'
'LoadHostSummary', 'ReloadHostSummaryList', 'JobIsFinished', 'SetTaskStyles'
];

View File

@ -39,24 +39,31 @@
angular.module('JobDetailHelper', ['Utilities', 'RestServices'])
.factory('ProcessEventQueue', ['$log', 'DigestEvent', 'JobIsFinished', function ($log, DigestEvent, JobIsFinished) {
.factory('ProcessEventQueue', ['$log', '$rootScope', 'DigestEvent', 'JobIsFinished', function ($log, $rootScope, DigestEvent, JobIsFinished) {
return function(params) {
var scope = params.scope,
eventQueue = params.eventQueue,
event;
processing = false;
function runTheQ() {
while (eventQueue.length > 0) {
var event;
processing = true;
while (!JobIsFinished(scope) && !scope.haltEventQueue && eventQueue.length > 0) {
event = eventQueue.pop();
$log.debug('read event: ' + event.id);
$log.debug('processing event: ' + event.id);
DigestEvent({ scope: scope, event: event });
}
if (!JobIsFinished(scope) && !scope.haltEventQueue) {
setTimeout( function() {
runTheQ();
}, 300);
}
processing = false;
//if (!JobIsFinished(scope) && !scope.haltEventQueue) {
// setTimeout( function() {
// runTheQ();
// }, 1000);
//}
}
runTheQ();
$rootScope.jobDetailInterval = window.setInterval(function() {
if (!processing && eventQueue.length > 0) {
runTheQ();
}
}, 1000);
};
}])