Skip to content

Commit

Permalink
Disconnect redis connections if worker, queues or schedules are ended.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed May 28, 2015
1 parent 3e515fc commit 0105f04
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/multiWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ multiWorker.prototype.cleanupWorker = function(worker){
});

if(self.options.toDisconnectProcessors === true){
worker.connection.redis.quit();
worker.connection.disconnect();
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var queue = function(options, jobs, callback){

queue.prototype.end = function(callback){
var self = this;
self.connection.redis.quit();
self.connection.disconnect();
process.nextTick(function(){
if(typeof callback === 'function'){ callback(); }
});
Expand Down
9 changes: 6 additions & 3 deletions lib/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ scheduler.prototype.end = function(callback) {
self.running = false;
if(self.processing === false){
clearTimeout(self.timer);
self.emit('end');
process.nextTick(function(){
if(typeof callback === 'function'){ callback(); }
self.queue.end(function() {
self.emit('end');
self.connection.disconnect();
process.nextTick(function(){
if(typeof callback === 'function'){ callback(); }
});
});
}else if(self.processing === true){
setTimeout(function(){
Expand Down
6 changes: 4 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ worker.prototype.end = function(callback) {
}, self.options.timeout);
}else{
self.untrack(self.name, self.stringQueues(), function(){
self.emit('end');
if(typeof callback === 'function'){ callback(); }
self.queueObject.end(function() {
self.emit('end');
if(typeof callback === 'function'){ callback(); }
});
});
}
};
Expand Down

0 comments on commit 0105f04

Please sign in to comment.