Job detail

Monitor socket connection and attempt to restart when status returns 'error' or continuously returns 'connecting'.
This commit is contained in:
Chris Houseknecht
2014-07-25 10:24:15 -04:00
parent 9af5cc3d6d
commit f0cb84d973

View File

@@ -19,7 +19,9 @@ function JobDetailController ($location, $rootScope, $scope, $compile, $routePar
api_complete = false, api_complete = false,
refresh_count = 0, refresh_count = 0,
lastEventId = 0, lastEventId = 0,
verbosity_options, job_type_options; verbosity_options,
job_type_options,
checkCount = 0;
scope.plays = []; scope.plays = [];
scope.hosts = []; scope.hosts = [];
@@ -77,20 +79,36 @@ function JobDetailController ($location, $rootScope, $scope, $compile, $routePar
"<p><i class=\"fa fa-circle failed-hosts-color\"></i> Failed</p>\n" + "<p><i class=\"fa fa-circle failed-hosts-color\"></i> Failed</p>\n" +
"<div class=\"popover-footer\"><span class=\"key\">esc</span> or click to close</div>\n"; "<div class=\"popover-footer\"><span class=\"key\">esc</span> or click to close</div>\n";
event_socket = Socket({ function openSocket() {
scope: scope, event_socket = Socket({
endpoint: "job_events" scope: scope,
}); endpoint: "job_events"
});
event_socket.init();
event_socket.on("job_events-" + job_id, function(data) {
if (api_complete && data.id > lastEventId) {
data.event = data.event_name;
DigestEvent({ scope: scope, event: data });
}
});
}
openSocket();
event_socket.init(); $rootScope.checkSocketConnectionInterval = setInterval(function() {
if (event_socket.checkStatus() === 'error' || checkCount > 2) {
event_socket.on("job_events-" + job_id, function(data) { // there's an error or we're stuck in a 'connecting' state. attempt to reconnect
if (api_complete && data.id > lastEventId) { $log.debug('job detail page: initializing and restarting socket connections');
data.event = data.event_name; event_socket = null;
DigestEvent({ scope: scope, event: data }); openSocket();
checkCount = 0;
} }
}); else if (event_socket.checkStatus() === 'connecting') {
checkCount++;
}
else {
checkCount = 0;
}
}, 3000);
if ($rootScope.removeJobStatusChange) { if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange(); $rootScope.removeJobStatusChange();