Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

If the queue is empty then the cb will be fired no matter what

  • Loading branch information...
commit 94d6a35d8c8db8b91e498f2db5a798b15d5024a2 1 parent cf4b1af
@grobot grobot authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 index.js
View
11 index.js
@@ -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;
@@ -86,8 +89,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.