I am using kue for long running operations. And I want to be able to track the operations progress.
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);
});
});
});
When I print the progress variable inside the .on('progress') it always prints out as 0.
According to the documentation:
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.
How is it possible to debug this? Is the documentation not up to date?
This seems to be problems with the kue.
After setting up a value for the data (which should be optional) it started working.
I also notice that sometimes the job stop having its progress event updated. The solution I found for that was to rename the job that is doing the work.