javascript - Is it possible to update a already created job in kue node js -


hi 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 delay time ,normally 3 hours .

now check every incoming request wants create new job , id .

as can see above code , when creating job add job id job .

so want check incoming id existing jobs' job_id s in queue , update existing job new params if matching id found .

so job queue have unique job_id every time :).

is possible ? , have searched lot no found , checked kue json api . can create , retrieve jobs , can not update existing records .

thanks in advance .

this not mentioned in documentation , examples, there update method job.

you can update jobs job_id way:

// have job_id var job_id_to_update = 1; // delayed jobs jobs.delayed( function( err, ids ) {   ids.foreach( function( id ) {     kue.job.get( id, function( err, job ) {       // check if job want       if (job.data.job_id === job_id_to_update) {           // change job properties           job.data.title = 'set title';           // save changes           job.update();       }     });   }); }); 

the full example here.

update: can consider using "native" job id, known kue. can job id when create job:

var myjob = jobs.create('myqueue', ...     .save(function(err) {         if (err) {             console.log( 'jobs.create.err', err );         }         var job_id = myjob.id;         // can send job_id client }); 

now can directly modify job without looping on list:

kue.job.get( id, function( err, job ) {   // change job properties   job.data.title = 'set title';   // save changes   job.update(); }); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -