Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from ifit/stopMonitoring

If the queue is empty then the cb will be fired no matter what
  • Loading branch information...
commit 6cf2772bfcfff1820f44fa06cc7bc5d4125fb2cd 2 parents fec21f8 + 94d6a35
scottrain scottrain authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 index.js
11 index.js
View
@@ -14,6 +14,7 @@ var PikaQueue = function(conf) {
this.notificationClient = redis.createClient(conf.port, conf.host, conf);
this.notify = {};
this.continueMonitoring = true;
+ this.mode = 'listening';
this.notificationClient.on('message', function(channel, message) {
message = JSON.parse(message);
@@ -50,7 +51,9 @@ PikaQueue.prototype.queueJob = function(queueName, jobDescription, cb) {
PikaQueue.prototype.monitorJobQueue = function(queueName, cb) {
var self = this;
+ self.mode = 'listening';
self.client.blpop(queueName, 0, function(err, job) {
+ self.mode = 'processing';
job = JSON.parse(job[1]);
if (job) {
var id = job.id;
@@ -89,8 +92,12 @@ PikaQueue.prototype.monitorJobQueue = function(queueName, cb) {
}
PikaQueue.prototype.stopMonitoring = function(cb) {
- this.continueMonitoring = false;
- this.stopMonitoringCallback = cb || function() {};
+ if (this.mode == 'listening') {
+ cb();
+ } else {
+ this.continueMonitoring = false;
+ this.stopMonitoringCallback = cb || function() {};
+ }
}
module.exports = PikaQueue;
Please sign in to comment.
Something went wrong with that request. Please try again.