Reputation: 986
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?
Upvotes: 0
Views: 1473
Reputation: 270
Quick answer, yes, you can use job.failed() or send an error back to done.
queue.process('myQueue', function(job, done){
console.log('IN HERE', job.state) // returns function
job.failed();
done(new Error('bad'));
});
However, it sounds like you want to handle the processing yourself. You can setup your own function like this.
queue.on('job enqueue', function(id, type){
console.log( 'Job %s got queued of type %s', id, type );
kue.Job.get(id, function(err, job){
if (err) return;
// do your custom processing here
if( something was processed ){
job.complete();
}else{
job.failed();
}
});
});
Here's a few more options you can also use.
job.inactive();
job.active();
job.complete();
job.delayed();
There's some examples on this page. https://github.com/Automattic/kue
Upvotes: 1