mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Job detail page refactor
If the queue grows beyond 500 events, reset and start over.
This commit is contained in:
@@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest, ProcessErrors, DigestEvents,
|
function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest, ProcessErrors,
|
||||||
SelectPlay, SelectTask, Socket, GetElapsed, SelectHost, FilterAllByHostName, DrawGraph, LoadHostSummary, ReloadHostSummaryList) {
|
DigestEvents, SelectPlay, SelectTask, Socket, GetElapsed, SelectHost, FilterAllByHostName, DrawGraph, LoadHostSummary, ReloadHostSummaryList,
|
||||||
|
JobIsFinished) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -20,13 +21,6 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
refresh_count = 0,
|
refresh_count = 0,
|
||||||
lastEventId = 0;
|
lastEventId = 0;
|
||||||
|
|
||||||
scope.plays = {};
|
|
||||||
scope.tasks = {};
|
|
||||||
scope.hosts = [];
|
|
||||||
scope.hostResults = [];
|
|
||||||
scope.hostResultsMap = {};
|
|
||||||
scope.hostsMap = {};
|
|
||||||
|
|
||||||
scope.search_all_tasks = [];
|
scope.search_all_tasks = [];
|
||||||
scope.search_all_plays = [];
|
scope.search_all_plays = [];
|
||||||
scope.job_status = {};
|
scope.job_status = {};
|
||||||
@@ -62,13 +56,6 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
data.event = data.event_name;
|
data.event = data.event_name;
|
||||||
$log.debug('push event: ' + data.id);
|
$log.debug('push event: ' + data.id);
|
||||||
event_queue.push(data);
|
event_queue.push(data);
|
||||||
|
|
||||||
/* if (api_complete && data.id > lastEventId) {
|
|
||||||
// api loading is complete, process incoming events
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Waiting on values from the api to load. Until then queue incoming events.
|
|
||||||
} */
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.removeAPIComplete) {
|
if (scope.removeAPIComplete) {
|
||||||
@@ -100,20 +87,8 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
}
|
}
|
||||||
lastEventId = Math.max(hostId, taskId, playId);
|
lastEventId = Math.max(hostId, taskId, playId);
|
||||||
|
|
||||||
// Only process queued events > the max event in memory
|
api_complete = true;
|
||||||
/*if (event_queue.length > 0) {
|
Wait('stop');
|
||||||
event_queue.forEach(function(event) {
|
|
||||||
if (event.id > lastEventId) {
|
|
||||||
events.push(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (events.length > 0) {
|
|
||||||
DigestEvents({
|
|
||||||
scope: scope,
|
|
||||||
events: events
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
DigestEvents({
|
DigestEvents({
|
||||||
scope: scope,
|
scope: scope,
|
||||||
@@ -121,11 +96,8 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
lastEventId: lastEventId
|
lastEventId: lastEventId
|
||||||
});
|
});
|
||||||
|
|
||||||
api_complete = true;
|
|
||||||
|
|
||||||
// Draw the graph
|
// Draw the graph
|
||||||
if (scope.job.status === 'successful' || scope.job.status === 'failed' || scope.job.status === 'error') {
|
if (JobIsFinished(scope)) {
|
||||||
// The job has already completed. graph values found on playbook stats
|
|
||||||
url = scope.job.related.job_events + '?event=playbook_on_stats';
|
url = scope.job.related.job_events + '?event=playbook_on_stats';
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.get()
|
Rest.get()
|
||||||
@@ -146,7 +118,6 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Draw the graph based on summary values in memory
|
// Draw the graph based on summary values in memory
|
||||||
Wait('stop');
|
|
||||||
DrawGraph({ scope: scope, resize: true });
|
DrawGraph({ scope: scope, resize: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -178,12 +149,22 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.removeJobReady) {
|
if (scope.removeLoadJobDetails) {
|
||||||
scope.removeJobReady();
|
scope.removeLoadJobDetails();
|
||||||
}
|
}
|
||||||
scope.removeJobReady = scope.$on('JobReady', function(e, events_url) {
|
scope.removeRefreshJobDetails = scope.$on('LoadJobDetails', function(e, events_url) {
|
||||||
// Job finished loading. Now get the set of plays
|
|
||||||
|
// Call to load all the job bits including, plays, tasks, hosts results and host summary
|
||||||
var url = scope.job.url + 'job_plays/?order_by=id';
|
var url = scope.job.url + 'job_plays/?order_by=id';
|
||||||
|
|
||||||
|
scope.plays = {};
|
||||||
|
scope.tasks = {};
|
||||||
|
scope.hostResults = [];
|
||||||
|
scope.hostResultsMap = {};
|
||||||
|
scope.hosts = [];
|
||||||
|
scope.hostsMap = {};
|
||||||
|
api_complete = false;
|
||||||
|
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.get()
|
Rest.get()
|
||||||
.success( function(data) {
|
.success( function(data) {
|
||||||
@@ -196,8 +177,7 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
// end date = starting date of the next event
|
// end date = starting date of the next event
|
||||||
end = data[idx + 1].started;
|
end = data[idx + 1].started;
|
||||||
}
|
}
|
||||||
else if (scope.job_status.status === 'successful' || scope.job_status.status === 'failed' ||
|
else if (JobIsFinished(scope)) {
|
||||||
scope.job_status.status === 'error' || scope.job_status.status === 'canceled') {
|
|
||||||
// this is the last play and the job already finished
|
// this is the last play and the job already finished
|
||||||
end = scope.job_status.finished;
|
end = scope.job_status.finished;
|
||||||
}
|
}
|
||||||
@@ -312,9 +292,11 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
else {
|
else {
|
||||||
scope.job_status.elapsed = '00:00:00';
|
scope.job_status.elapsed = '00:00:00';
|
||||||
}
|
}
|
||||||
|
if (scope.myInterval) {
|
||||||
|
window.clearInterval(scope.myInterval);
|
||||||
|
}
|
||||||
scope.setSearchAll('host');
|
scope.setSearchAll('host');
|
||||||
scope.$emit('JobReady', data.related.job_events);
|
scope.$emit('LoadJobDetails', data.related.job_events);
|
||||||
scope.$emit('GetCredentialNames', data);
|
scope.$emit('GetCredentialNames', data);
|
||||||
})
|
})
|
||||||
.error(function(data, status) {
|
.error(function(data, status) {
|
||||||
@@ -675,9 +657,6 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
ReloadHostSummaryList({
|
ReloadHostSummaryList({
|
||||||
scope: scope
|
scope: scope
|
||||||
});
|
});
|
||||||
//setTimeout(function() {
|
|
||||||
// SelectPlay({ scope: scope, id: scope.activePlay });
|
|
||||||
//}, 2000);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -722,5 +701,5 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
|
|
||||||
JobDetailController.$inject = [ '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath', 'Wait',
|
JobDetailController.$inject = [ '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath', 'Wait',
|
||||||
'Rest', 'ProcessErrors', 'DigestEvents', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'SelectHost', 'FilterAllByHostName', 'DrawGraph',
|
'Rest', 'ProcessErrors', 'DigestEvents', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'SelectHost', 'FilterAllByHostName', 'DrawGraph',
|
||||||
'LoadHostSummary', 'ReloadHostSummaryList'
|
'LoadHostSummary', 'ReloadHostSummaryList', 'JobIsFinished'
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -40,35 +40,43 @@
|
|||||||
angular.module('JobDetailHelper', ['Utilities', 'RestServices'])
|
angular.module('JobDetailHelper', ['Utilities', 'RestServices'])
|
||||||
|
|
||||||
.factory('DigestEvents', ['$log', 'UpdatePlayStatus', 'UpdateHostStatus', 'AddHostResult', 'SelectPlay', 'SelectTask',
|
.factory('DigestEvents', ['$log', 'UpdatePlayStatus', 'UpdateHostStatus', 'AddHostResult', 'SelectPlay', 'SelectTask',
|
||||||
'GetHostCount', 'GetElapsed', 'UpdateTaskStatus', 'DrawGraph', 'LoadHostSummary',
|
'GetHostCount', 'GetElapsed', 'UpdateTaskStatus', 'DrawGraph', 'LoadHostSummary', 'JobIsFinished',
|
||||||
function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, SelectTask, GetHostCount, GetElapsed,
|
function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, SelectTask, GetHostCount, GetElapsed,
|
||||||
UpdateTaskStatus, DrawGraph, LoadHostSummary) {
|
UpdateTaskStatus, DrawGraph, LoadHostSummary, JobIsFinished) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
queue = params.queue,
|
queue = params.queue,
|
||||||
lastEventId = params.lastEventId,
|
lastEventId = params.lastEventId;
|
||||||
myInterval;
|
|
||||||
|
function popEvent() {
|
||||||
|
$log.debug('queue length: ' + queue.length);
|
||||||
|
if (queue.length > 0 && queue.length < 500) {
|
||||||
|
var event = queue.splice(0,1);
|
||||||
|
if (event[0].id > lastEventId) {
|
||||||
|
$log.debug('processing event: ' + event[0].id);
|
||||||
|
scope.$emit('ProcessEvent', event[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (queue.length > 500) {
|
||||||
|
// if we get too far behind, clear the queue and refresh
|
||||||
|
queue = [];
|
||||||
|
scope.emit('LoadJob');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (scope.removeGetNextEvent) {
|
if (scope.removeGetNextEvent) {
|
||||||
scope.removeGetNextEvent();
|
scope.removeGetNextEvent();
|
||||||
}
|
}
|
||||||
scope.removeGetNextEvent = scope.$on('GetNextEvent', function() {
|
scope.removeGetNextEvent = scope.$on('GetNextEvent', function() {
|
||||||
if (myInterval) {
|
if (scope.myInterval) {
|
||||||
window.clearInterval(myInterval);
|
window.clearInterval(scope.myInterval);
|
||||||
}
|
}
|
||||||
if (scope.job.status !== 'successful' && scope.job.status !== 'failed' && scope.job.status !== 'error') {
|
popEvent();
|
||||||
myInterval = window.setInterval(function() {
|
if (!JobIsFinished(scope)) {
|
||||||
var event;
|
scope.myInterval = window.setInterval(function() {
|
||||||
$log.debug('checking queue length is: ' + queue.length);
|
popEvent();
|
||||||
if (queue.length > 0) {
|
}, 600);
|
||||||
event = queue.splice(0,1);
|
|
||||||
if (event[0].id > lastEventId) {
|
|
||||||
$log.debug('processing event: ' + event[0].id);
|
|
||||||
scope.$emit('ProcessEvent', event[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -79,11 +87,11 @@ function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, Se
|
|||||||
var hostCount;
|
var hostCount;
|
||||||
$log.debug('handling event: ' + event.id);
|
$log.debug('handling event: ' + event.id);
|
||||||
if (event.event === 'playbook_on_start') {
|
if (event.event === 'playbook_on_start') {
|
||||||
if (scope.job_status.status!== 'failed' && scope.job_status.status !== 'canceled' &&
|
if (!JobIsFinished(scope)) {
|
||||||
scope.job_status.status !== 'error' && scope.job_status !== 'successful') {
|
|
||||||
scope.job_status.started = event.created;
|
scope.job_status.started = event.created;
|
||||||
scope.job_status.status = 'running';
|
scope.job_status.status = 'running';
|
||||||
}
|
}
|
||||||
|
scope.$emit('GetNextEvent');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.event === 'playbook_on_play_start') {
|
if (event.event === 'playbook_on_play_start') {
|
||||||
@@ -94,6 +102,9 @@ function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, Se
|
|||||||
status: (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'none',
|
status: (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'none',
|
||||||
elapsed: '00:00:00'
|
elapsed: '00:00:00'
|
||||||
};
|
};
|
||||||
|
if (scope.plays.length > 1) {
|
||||||
|
DrawGraph({ scope: scope, resize: false });
|
||||||
|
}
|
||||||
SelectPlay({
|
SelectPlay({
|
||||||
scope: scope,
|
scope: scope,
|
||||||
id: event.id
|
id: event.id
|
||||||
@@ -135,6 +146,7 @@ function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, Se
|
|||||||
changed: event.changed,
|
changed: event.changed,
|
||||||
modified: event.modified
|
modified: event.modified
|
||||||
});
|
});
|
||||||
|
scope.$emit('GetNextEvent');
|
||||||
}
|
}
|
||||||
if (event.event === 'playbook_on_no_hosts_matched') {
|
if (event.event === 'playbook_on_no_hosts_matched') {
|
||||||
UpdatePlayStatus({
|
UpdatePlayStatus({
|
||||||
@@ -273,11 +285,18 @@ function($log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, SelectPlay, Se
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.$emit('GetNextEvent');
|
scope.$emit('GetNextEvent'); // Start checking the queue
|
||||||
|
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
.factory('JobIsFinished', [ function() {
|
||||||
|
return function(scope) {
|
||||||
|
return (scope.job_status.status === 'failed' || scope.job_status.status === 'canceled' ||
|
||||||
|
scope.job_status.status === 'error' || scope.job_status.status === 'successful');
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
//Get the # of expected hosts for a task by looking at the number
|
//Get the # of expected hosts for a task by looking at the number
|
||||||
//on the very first task for a play
|
//on the very first task for a play
|
||||||
.factory('GetHostCount', [ 'FindFirstTaskofPlay', function(FindFirstTaskofPlay) {
|
.factory('GetHostCount', [ 'FindFirstTaskofPlay', function(FindFirstTaskofPlay) {
|
||||||
|
|||||||
Reference in New Issue
Block a user