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)
在以下情况下,我得到的错误是一致的:
我不确定Queue.client
是否为null。如果是,那么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;
};
注意:queue
是Kue
的实例,client
是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提出了同样的问题(问题):
还没有反应..。
任何想法/想法!怎么解决这个问题..?
发布于 2016-03-05 11:55:45
由于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});
});
});
};
就这样!
希望这能帮到别人!!
干杯。
https://stackoverflow.com/questions/35626748
复制相似问题