Rebase of devel (w/ channels) + socket rework for new job details

Replacing old socket.io receiver w/ new websocket receivers
This commit is contained in:
jaredevantabor
2016-10-10 11:22:56 -07:00
parent 648bd3d1a0
commit 3ade961e92
3 changed files with 33 additions and 32 deletions

View File

@@ -1,3 +1,4 @@
<<<<<<< 4cf6a946a1aa14b7d64a8e1e8dabecfd3d056f27
//<<<<<<< bc59236851902d7c768aa26abdb7dc9c9dc27a5a //<<<<<<< bc59236851902d7c768aa26abdb7dc9c9dc27a5a
/************************************************* /*************************************************
* Copyright (c) 2016 Ansible, Inc. * Copyright (c) 2016 Ansible, Inc.
@@ -46,6 +47,8 @@
// controller: 'JobDetailController' // controller: 'JobDetailController'
// }; // };
//======= //=======
=======
>>>>>>> Rebase of devel (w/ channels) + socket rework for new job details
// /************************************************* // /*************************************************
// * Copyright (c) 2016 Ansible, Inc. // * Copyright (c) 2016 Ansible, Inc.
// * // *
@@ -61,6 +64,12 @@
// parent: 'jobs', // parent: 'jobs',
// label: "{{ job.id }} - {{ job.name }}" // label: "{{ job.id }} - {{ job.name }}"
// }, // },
// socket: {
// "groups":{
// "jobs": ["status_changed", "summary"],
// "job_events": []
// }
// },
// resolve: { // resolve: {
// jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) { // jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) {
// if (!$rootScope.event_socket) { // if (!$rootScope.event_socket) {

View File

@@ -76,13 +76,6 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'count', '$scope', 'Pa
$scope.hostCount = getTotalHostCount(count.val); $scope.hostCount = getTotalHostCount(count.val);
$scope.countFinished = count.countFinished; $scope.countFinished = count.countFinished;
// Process incoming job status changes
$rootScope.$on('JobStatusChange-jobDetails', function(e, data) {
if (parseInt(data.unified_job_id, 10) === parseInt($scope.job.id,10)) {
$scope.job.status = data.status;
}
});
// EVENT STUFF BELOW // EVENT STUFF BELOW
// just putting the event queue on scope so it can be inspected in the // just putting the event queue on scope so it can be inspected in the
@@ -150,14 +143,26 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'count', '$scope', 'Pa
}; };
getEvents($scope.job.related.job_events); getEvents($scope.job.related.job_events);
// PUSH! process incoming job events // Processing of job_events messages from the websocket
$rootScope.event_socket.on("job_events-" + $scope.job.id, function(data) { $scope.$on(`ws-job_events-${$scope.job.id}`, function(e, data) {
processEvent(data); processEvent(data);
}); });
// STOP! stop listening to job events // Processing of job-status messages from the websocket
$scope.$on('$destroy', function() { $scope.$on(`ws-jobs`, function(e, data) {
$rootScope.event_socket.removeAllListeners("job_events-" + if (parseInt(data.unified_job_id, 10) === parseInt($scope.job.id,10)) {
$scope.job.id); $scope.job.status = data.status;
}
}); });
// The code below was used in the old job detail controller,
// and is for processing the 'Job Summary' event that is delivered
// for a completed job. Not sure if we have an equivalent function
// at this point. TODO: write function to handle Job Summary
// scope.$on('ws-jobs-summary', function() {
// // the job host summary should now be available from the API
// $log.debug('Trigging reload of job_host_summaries');
// scope.$emit('InitialLoadComplete');
// });
}]; }];

View File

@@ -15,6 +15,12 @@ export default {
parent: 'jobs', parent: 'jobs',
label: '{{ job.id }} - {{ job.name }}' label: '{{ job.id }} - {{ job.name }}'
}, },
socket: {
"groups":{
"jobs": ["status_changed", "summary"],
"job_events": []
}
},
resolve: { resolve: {
// the GET for the particular job // the GET for the particular job
jobData: ['Rest', 'GetBasePath', '$stateParams', '$q', '$state', 'Alert', function(Rest, GetBasePath, $stateParams, $q, $state, Alert) { jobData: ['Rest', 'GetBasePath', '$stateParams', '$q', '$state', 'Alert', function(Rest, GetBasePath, $stateParams, $q, $state, Alert) {
@@ -122,25 +128,6 @@ export default {
}); });
return val.promise; return val.promise;
}], }],
// This gives us access to the job events socket so we can start
// listening for updates we need to make for the ui as data comes in
//
// TODO: we could probably make this better by not initing
// job_events for completed jobs
jobEventsSocket: ['Socket', '$rootScope', function(Socket, $rootScope) {
if (!$rootScope.event_socket) {
$rootScope.event_socket = Socket({
scope: $rootScope,
endpoint: "job_events"
});
$rootScope.event_socket.init();
// returns should really be providing $rootScope.event_socket
// otherwise, we have to inject the entire $rootScope into the controller
return true;
} else {
return true;
}
}],
// This clears out the event queue, otherwise it'd be full of events // This clears out the event queue, otherwise it'd be full of events
// for previous job results the user had navigated to // for previous job results the user had navigated to
eventQueueInit: ['eventQueue', function(eventQueue) { eventQueueInit: ['eventQueue', function(eventQueue) {