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
3 changed files with 31 additions and 9 deletions

View File

@@ -207,6 +207,11 @@ export default
} }
UpdateDOM({ scope: scope }); 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(); openSocket();

View File

@@ -211,7 +211,15 @@ angular.module('SocketIO', ['Utilities'])
}, },
getUrl: function() { getUrl: function() {
return url; 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 // Open up a socket for events depending on the type of job
function openSockets() { function openSockets() {
if ($state.current.name === 'jobDetail') { if ($state.current.name === 'jobDetail') {
$log.debug("socket watching on job_events-" + job_id); $log.debug("socket watching on job_events-" + job_id);
$rootScope.event_socket.on("job_events-" + job_id, function() { $rootScope.event_socket.on("job_events-" + job_id, function() {
$log.debug("socket fired on job_events-" + job_id); $log.debug("socket fired on job_events-" + job_id);
if (api_complete) { if (api_complete) {
event_queue++; 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') { if ($state.current.name === 'adHocJobStdout') {
$log.debug("socket watching on ad_hoc_command_events-" + job_id); $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++; 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(); openSockets();