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

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

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)

在以下情况下,我经常收到此错误:

  1. 在浏览器中打开 kui-ui 仪表板 window
  2. 执行正常关机

我不确定 Queue.client 是否应该为空。如果是,那么 Queue.prototype.card 在调用 this.client.card 之前应该首先检查 this.client 是否存在。与 Queue.prototype.cardByType

相同

这是我的 api 路由 dashboard/stop 代码(即停止进程并刷新缓存):

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;

};

注意:queueKue 的实例,clientredis 的实例:

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

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

同样的问题(issue)也有人在github上提出:

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

还没有回复..

任何Idea/thoughts!如何获得此修复..?

问题是由于 Queue.prototype.shutdown 实现破坏了客户端(即 redis)实例,这就是为什么当它调用 Queue.prototype.cardQueue.prototype.cardByType 然后它抛出那个错误..

至于我的目标是以某种方式停止(暂停)队列进程然后再次恢复它..所以我做了类似的事情而不是使用 Queue.prototype.shutdown 我宁愿使用 Worker.prototype.shutdown 暂停工人的(进程)..

queue.js(样本):

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(样本):

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});
    });
  });
};

就是这样!

希望这对其他人有帮助!!

干杯。