0
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 仪表板
  2. 执行正常关机

我不确定它是否应该为Queue.client空。如果是,那么应该在调用之前Queue.prototype.card先检查是否存在。与this.clientthis.client.cardQueue.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;

};

注意:queueKueclient的一个实例redis

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

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

github上也提出了相同的问题(issue):

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

而且还没反应。。

任何想法/想法!如何得到这个修复..?

4

1 回答 1

0

问题是由于Queue.prototype.shutdown实现破坏客户端(即redis)实例而引起的,这就是为什么当它调用Queue.prototype.card然后Queue.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});
    });
  });
};

而已!

希望这对其他人有帮助!

干杯。

于 2016-03-05T11:55:45.050 回答