Remove event socket listeners when the scope that created them is destroyed. This should fix #2121 where an existing jobs standard out was erroneously being updated after a new job launch.

This commit is contained in:
Michael Abashian 2016-06-02 16:15:38 -04:00
parent 1881af8e77
commit 68365effb8
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.event_socket.removeAllListeners("ad_hoc_command_events-" + job_id);
});
}
// TODO: do we need to add socket listeners for scmUpdateStdout, inventorySyncStdout, managementJobStdout?
}
openSockets();