Merge pull request #2145 from mabashian/standard-out-log

Remove job details/stdout event socket listeners when $scope is destroyed
This commit is contained in:
Michael Abashian 2016-06-03 11:38:21 -04:00
commit e4d08e7cb1
3 changed files with 31 additions and 9 deletions

View File

@ -207,6 +207,11 @@ export default
}
UpdateDOM({ scope: scope });
});
// Unbind $rootScope socket event binding(s) so that they don't get triggered
// in another instance of this controller
scope.$on('$destroy', function() {
$rootScope.event_socket.removeAllListeners("job_events-" + job_id);
});
}
openSocket();

View File

@ -211,7 +211,15 @@ angular.module('SocketIO', ['Utilities'])
},
getUrl: function() {
return url;
}
},
removeAllListeners: function (eventName) {
var self = this;
if(self){
if(self.socket){
self.socket.removeAllListeners(eventName);
}
}
},
};
};
}]);

View File

@ -21,13 +21,18 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
// Open up a socket for events depending on the type of job
function openSockets() {
if ($state.current.name === 'jobDetail') {
$log.debug("socket watching on job_events-" + job_id);
$rootScope.event_socket.on("job_events-" + job_id, function() {
$log.debug("socket fired on job_events-" + job_id);
if (api_complete) {
event_queue++;
}
});
$log.debug("socket watching on job_events-" + job_id);
$rootScope.event_socket.on("job_events-" + job_id, function() {
$log.debug("socket fired on job_events-" + job_id);
if (api_complete) {
event_queue++;
}
});
// Unbind $rootScope socket event binding(s) so that they don't get triggered
// in another instance of this controller
$scope.$on('$destroy', function() {
$rootScope.event_socket.removeAllListeners("job_events-" + job_id);
});
}
if ($state.current.name === 'adHocJobStdout') {
$log.debug("socket watching on ad_hoc_command_events-" + job_id);
@ -37,8 +42,12 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
event_queue++;
}
});
// Unbind $rootScope socket event binding(s) so that they don't get triggered
// in another instance of this controller
$scope.$on('$destroy', function() {
$rootScope.adhoc_event_socket.removeAllListeners("ad_hoc_command_events-" + job_id);
});
}
// TODO: do we need to add socket listeners for scmUpdateStdout, inventorySyncStdout, managementJobStdout?
}
openSockets();