Skip to content

Commit

Permalink
Merge pull request #78 from arthurschreiber/patch-1
Browse files Browse the repository at this point in the history
Ensure redis connections get released
  • Loading branch information
evantahler committed May 28, 2015
2 parents bf847c4 + 0105f04 commit 2c558ef
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ connection.prototype.connect = function(callback){

connection.prototype.disconnect = function(){
var self = this;
return self.redis.quit();
// Only disconnect if we established the redis connection on our own.
if (!self.options.redis) {
return self.redis.quit();
}
}

connection.prototype.key = function(){
Expand Down
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 2c558ef

Please sign in to comment.