I am creating jobs using Kue.
jobs.create('myQueue', { 'title':'test', 'job_id': id ,'params': params } )
.delay(milliseconds)
.removeOnComplete( true )
.save(function(err) {
if (err) {
console.log( 'jobs.create.err', err );
}
});
Every job has a delay time, and normally it is 3 hours.
Now I will to check every ining request that wants to create a new job and get the id .
As you can see from the above code, when I am creating a job I will add the job id to the job.
So now I want to check the ining id with the existing jobs' job_id s in the queue and update that existing job with the new parameters if a matching id found.
So my job queue will have unique job_id every time :).
Is it possible? I have searched a lot, but no help found. I checked the kue JSON API. but it only can create and get retrieve jobs, can not update existing records.
I am creating jobs using Kue.
jobs.create('myQueue', { 'title':'test', 'job_id': id ,'params': params } )
.delay(milliseconds)
.removeOnComplete( true )
.save(function(err) {
if (err) {
console.log( 'jobs.create.err', err );
}
});
Every job has a delay time, and normally it is 3 hours.
Now I will to check every ining request that wants to create a new job and get the id .
As you can see from the above code, when I am creating a job I will add the job id to the job.
So now I want to check the ining id with the existing jobs' job_id s in the queue and update that existing job with the new parameters if a matching id found.
So my job queue will have unique job_id every time :).
Is it possible? I have searched a lot, but no help found. I checked the kue JSON API. but it only can create and get retrieve jobs, can not update existing records.
Share Improve this question edited Jul 9, 2018 at 10:04 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jan 21, 2016 at 9:28 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges194 bronze badges 2- Have you tried the update method ? github./Automattic/kue/blob/master/lib/queue/job.js#L807 – Hugeen Commented Jan 28, 2016 at 8:44
- Use the json API to GET /job/<id> before creating the job. If it exists (status 200), update the job. If it doesn't exist (status 404), create the job. – Kyle Pittman Commented Feb 3, 2016 at 15:21
2 Answers
Reset to default 13 +100This is not mentioned in the documentation and examples, but there is an update method for a job
.
You can update your jobs by job_id
this way:
// you have the job_id
var job_id_to_update = 1;
// get delayed jobs
jobs.delayed( function( err, ids ) {
ids.forEach( function( id ) {
kue.Job.get( id, function( err, job ) {
// check if this is job we want
if (job.data.job_id === job_id_to_update) {
// change job properties
job.data.title = 'set another title';
// save changes
job.update();
}
});
});
});
The full example is here.
Update: you can also consider using the "native" job ID, which is known for kue. You can get the job id when you create the job:
var myjob = jobs.create('myQueue', ...
.save(function(err) {
if (err) {
console.log( 'jobs.create.err', err );
}
var job_id = myjob.id;
// you can send job_id back to the client
});
Now you can directly modify the job without looping over the list:
kue.Job.get( id, function( err, job ) {
// change job properties
job.data.title = 'set another title';
// save changes
job.update();
});
Just wanted to post an update. This ticket https://github./Automattic/kue/issues/505 has the answer for my question.