From 3e515fcf9781aac92d4a5eda66871a2f13568167 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Thu, 28 May 2015 16:59:58 +0200 Subject: [PATCH 1/2] Only disconnect connections that were established by node-resque. --- lib/connection.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/connection.js b/lib/connection.js index e53c8812..003a2df0 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -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(){ From 0105f04036ff597ac58095646fb5de3456314a74 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Thu, 28 May 2015 17:12:38 +0200 Subject: [PATCH 2/2] Disconnect redis connections if worker, queues or schedules are `end`ed. --- lib/multiWorker.js | 2 +- lib/queue.js | 2 +- lib/scheduler.js | 9 ++++++--- lib/worker.js | 6 ++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/multiWorker.js b/lib/multiWorker.js index ca9b6d28..69afe5db 100644 --- a/lib/multiWorker.js +++ b/lib/multiWorker.js @@ -170,7 +170,7 @@ multiWorker.prototype.cleanupWorker = function(worker){ }); if(self.options.toDisconnectProcessors === true){ - worker.connection.redis.quit(); + worker.connection.disconnect(); } }; diff --git a/lib/queue.js b/lib/queue.js index cefcd427..8429317a 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -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(); } }); diff --git a/lib/scheduler.js b/lib/scheduler.js index 1f0e50de..793e5fa6 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -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(){ diff --git a/lib/worker.js b/lib/worker.js index 0fd07380..ba40d990 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -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(); } + }); }); } };