Kue - TypeError: Cannot read property 'zcard' of null

277 Views Asked by At
TypeError: Cannot read property 'zcard' of null
    at Queue.card (/Users/narain/Sites/integrity-automation/node_modules/kue/lib/kue.js:513:14)
    at Queue.inactiveCount (/Users/narain/Sites/integrity-automation/node_modules/kue/lib/kue.js:616:17)
    at _ (/Users/narain/Sites/integrity-automation/node_modules/kue/lib/http/routes/json.js:318:19)
    at exports.stats (/Users/narain/Sites/integrity-automation/node_modules/kue/lib/http/routes/json.js:41:3)
    at Layer.handle [as handle_request] (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/route.js:131:13)
    at /Users/narain/Sites/integrity-automation/node_modules/kue/lib/http/middleware/provides.js:11:36
    at Layer.handle [as handle_request] (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/layer.js:95:5)
    at /Users/narain/Sites/integrity-automation/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/narain/Sites/integrity-automation/node_modules/express/lib/router/index.js:271:10)
    at SendStream.error (/Users/narain/Sites/integrity-automation/node_modules/serve-static/index.js:120:7)
    at emitOne (events.js:77:13)
    at SendStream.emit (events.js:169:7)
    at SendStream.error (/Users/narain/Sites/integrity-automation/node_modules/send/index.js:245:17)
    at SendStream.onStatError (/Users/narain/Sites/integrity-automation/node_modules/send/index.js:356:12)
    at next (/Users/narain/Sites/integrity-automation/node_modules/send/index.js:630:16)
    at onstat (/Users/narain/Sites/integrity-automation/node_modules/send/index.js:619:14)
    at FSReqWrap.oncomplete (fs.js:82:15)

I 'm getting this error pretty consistently under the following conditions:

  1. Have kui-ui dashboard open in a browser window
  2. perform graceful shutdown

I'm not certain if it is expected for Queue.client to be null. If it is, then Queue.prototype.card should first check if this.client exists before calling this.client.card. Same with Queue.prototype.cardByType

Here's my api route dashboard/stop code (i.e., stops the process and flush the cache):

exports.stop = function(success, failure) {

  let shutdown = new Promise((resolve, reject) => {
    debug('shutting down queue');
    queue.shutdown().then(() => {
      client.flushdb(); // flushing the redis server
      debug('redis is flushed');
      resolve({success: true});
    },
    (err) => {
      reject(err);
    });
  });

  return shutdown;

};

Note: queue is an instance of Kue and client is of redis:

let queue = require('kue').createQueue({prefix: '', redis: config.get('redisurl'), jobEvents: false});

let client = require('redis').createClient({
  'url': config.get('redis') // redis-url
});

Same question (issue) have also been raised on github:

  1. https://github.com/Automattic/kue/issues/825
  2. https://github.com/StreetHub/kue-ui/issues/23

And have no response yet..

Any Idea/thoughts! How to get this fix..?

1

There are 1 best solutions below

0
On BEST ANSWER

Issue was causing because of Queue.prototype.shutdown implementation destroy client (i.e., redis) instance that's why when it call Queue.prototype.cardand Queue.prototype.cardByType then it throws that error..

As for as my aim was to somehow stop (pause) the queue process and then resume it again.. so i have done something like that instead of using Queue.prototype.shutdown i have rather used Worker.prototype.shutdown which pauses the worker's (process)..

queue.js (sample):

this.queue = kue.createQueue({prefix: opts.prefix, redis: opts.redis, jobEvents: false, disableSearch: false}); // kue instance

stopAllWorkers() {
    return new Promise((resolve, reject) => {
      var length = this.queue.workers.length;
      this.queue.workers.forEach((worker) => {
        worker.shutdown(() => {
          if (--length === 0) {
            resolve();
          }
        });
      });
    });
  }

serverRunner.js (sample):

var queue = require('./queue');

exports.start = function(success, failure) {
    // resume the queue process
}

exports.stop = function(success, failure) {
  return new Promise((resolve, reject) => {
    queue.removeAllListeners();
    queue.stopAllWorkers().then(() => {
      debug('Queue All workers stopped!!');
      resolve({success: true});
    });
  });
};

That's it!

Hope this help others!!

Cheers.