kue工作进度总是0
kue job progress always 0
我正在使用 kue 进行长时间的 运行 操作。我希望能够跟踪操作进度。
var kue = require('kue'),
queue = kue.createQueue();
var daJob = queue.create('da', {
title: 'data analysis'
, batchSize: req.params.batchSize
}).save( function(err){
if( !err ) console.log( daJob.id );
});
// listeners on the different events
daJob.on('complete', function(result){
console.log('Job completed with data ', result);
daJob.remove();
}).on('failed attempt', function(errorMessage, doneAttempts){
console.log('Job failed');
}).on('failed', function(errorMessage){
console.log('Job failed');
}).on('progress', function(progress, data){
console.log('progress'+progress);
});
queue.process('da', function(daJob, done){
var total = 0;
async.parallel([
function(callback){
Col1.count({}, function(err, c) {
total += c;
callback();
});
},
function(callback){
Col2.count({}, function(err, c) {
total += c;
callback();
});
},
function(callback){
Col3.count({}, function(err, c) {
total += c;
callback();
});
}], function done(err, results) {
if (err) console.error(err);
var count = 0;
async.parallel([
function (callback) {
var cur1 = col1.find().lean().cursor({batchSize: req.params.batchSize});
cur1.on('data', function (mobileTN) {
count++;
functions.workMobileRecord(mobileTN);
console.log('mobile ' +count/total);
daJob.progress(count,total);
});
cur1.on('close', function () {
callback();
});
},
function (callback) {
var cur2 = col2.find().lean().cursor({batchSize: req.params.batchSize});
cur2.on('data', function (fixedTN) {
count++;
console.log(count/total);
daJob.progress(count,total);
});
cur2.on('close', function () {
callback();
});
},
function (callback){
var cur3 = col3.find().lean().cursor({batchSize:req.params.batchSize});
cur3.on('data', function(videoTN){
count++;
console.log(count/total);
daJob.progress(count,total);
});
cur3.on('close', function () {
callback();
});
}], function done(err, results) {
if (err) console.error(err);
done(results);
});
});
});
当我在 .on('progress') 中打印进度变量时,它总是打印为 0。
根据文档:
Job progress is extremely useful for long-running jobs such as video
conversion. To update the job's progress simply invoke
job.progress(completed, total [, data]):
job.progress(frames, totalFrames); data can be used to pass extra
information about the job. For example a message or an object with
some extra contextual data to the current status.
如何调试这个?文档不是最新的吗?
这似乎是 kue 的问题。
为数据设置值(应该是可选的)后它开始工作。
我还注意到有时作业会停止更新其进度事件。我找到的解决方案是重命名正在执行该工作的作业。
我正在使用 kue 进行长时间的 运行 操作。我希望能够跟踪操作进度。
var kue = require('kue'),
queue = kue.createQueue();
var daJob = queue.create('da', {
title: 'data analysis'
, batchSize: req.params.batchSize
}).save( function(err){
if( !err ) console.log( daJob.id );
});
// listeners on the different events
daJob.on('complete', function(result){
console.log('Job completed with data ', result);
daJob.remove();
}).on('failed attempt', function(errorMessage, doneAttempts){
console.log('Job failed');
}).on('failed', function(errorMessage){
console.log('Job failed');
}).on('progress', function(progress, data){
console.log('progress'+progress);
});
queue.process('da', function(daJob, done){
var total = 0;
async.parallel([
function(callback){
Col1.count({}, function(err, c) {
total += c;
callback();
});
},
function(callback){
Col2.count({}, function(err, c) {
total += c;
callback();
});
},
function(callback){
Col3.count({}, function(err, c) {
total += c;
callback();
});
}], function done(err, results) {
if (err) console.error(err);
var count = 0;
async.parallel([
function (callback) {
var cur1 = col1.find().lean().cursor({batchSize: req.params.batchSize});
cur1.on('data', function (mobileTN) {
count++;
functions.workMobileRecord(mobileTN);
console.log('mobile ' +count/total);
daJob.progress(count,total);
});
cur1.on('close', function () {
callback();
});
},
function (callback) {
var cur2 = col2.find().lean().cursor({batchSize: req.params.batchSize});
cur2.on('data', function (fixedTN) {
count++;
console.log(count/total);
daJob.progress(count,total);
});
cur2.on('close', function () {
callback();
});
},
function (callback){
var cur3 = col3.find().lean().cursor({batchSize:req.params.batchSize});
cur3.on('data', function(videoTN){
count++;
console.log(count/total);
daJob.progress(count,total);
});
cur3.on('close', function () {
callback();
});
}], function done(err, results) {
if (err) console.error(err);
done(results);
});
});
});
当我在 .on('progress') 中打印进度变量时,它总是打印为 0。
根据文档:
Job progress is extremely useful for long-running jobs such as video conversion. To update the job's progress simply invoke job.progress(completed, total [, data]):
job.progress(frames, totalFrames); data can be used to pass extra information about the job. For example a message or an object with some extra contextual data to the current status.
如何调试这个?文档不是最新的吗?
这似乎是 kue 的问题。
为数据设置值(应该是可选的)后它开始工作。
我还注意到有时作业会停止更新其进度事件。我找到的解决方案是重命名正在执行该工作的作业。