Friday 21 April 2017

Updating job status in KUE node js

I create a job:

var kue = require('kue');
var queue = kue.createQueue();

//name of the queue is myQueue
var job = queue.create('myQueue', {
    from: 'process1',
    type: 'testMessage',
    data: {
        msg: 'Hello world!'
    }
}).save(function(err) {
    if (err) {
        console.log('Unable to save ' + err);
    } else {
        console.log('Job ' + job.id + ' saved to the queue.');
    }
});

Is there a way I can update the job status (i.e. active, failed, in progress) myself? So for example:

The consumer picks up the job:

queue.process('myQueue', function(job, done){
  console.log('IN HERE', job.state) // returns function
});

This is the function that is returned from the above:

function ( state, fn ) {
  if( 0 == arguments.length ) return this._state;
  var client   = this.client
    , fn       = fn || noop;
  var oldState = this._state;
  var multi    = client.multi();

And I want to hardcode a job state e.g. job.state = 'failed' and allow myself to update the job status when I want to?

Is this possible in Kue?



via deeveeABC

No comments:

Post a Comment