1

Is there any known API for getting number of jobs in Kue? For example, I want to get number of inactive jobs.

Right now I have this portion of code that gets the JOBS.

var kue = require('kue'),
jobs = kue.createQueue();

kue.Job.rangeByType ('job', 'failed', 0, 10, 'asc', function (err, selectedJobs) {
    selectedJobs.forEach(function (job) {
        job.state('inactive').save();
    });
});

I can use selectedJobs.length. However, this is bad form performance perspective.

Thanks in advance

abdawoud
  • 219
  • 4
  • 16

1 Answers1

2

You can use the inactiveCount function of kue to get the number of inactive jobs.

var kue = require('kue')
    , jobs = kue.createQueue();
var findJobCount = function(){
    jobs.activeCount(function(err,count){
        if(!err)
            console.log('Active: ',count);
    });
    jobs.inactiveCount(function(err,count){
        if(!err)
            console.log('Inactive: ',count);
    });
}

findJobCount();

The function in kue.js (https://github.com/LearnBoost/kue/blob/master/lib/kue.js#L453-L459)

/**
 * Inactive jobs (queued) count.
 */

Queue.prototype.inactiveCount = function (fn) {
    return this.card('inactive', fn);
};
Sarita
  • 837
  • 11
  • 19