Thursday, 8 June 2017

Only move job into Active when condition is met - Kue node js

Is the following possible?

I was wondering if its possible to hold the job in a queued state before putting it into active only when it meets a condition. Example:

This is what the jobs look like =

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

This is my queue.process =

queue.process('myQueue', 4, function(job, done) {
  console.log('job', job.data)
  handleMessage(job, done); 
});

As soon as the job is picked up my queue.process, it is moved to active state. However, I only want to move the job into active state, when there is something in the database, like so:

 myDatabase.find(function(err, docs) {
   if(docs){
      //move the job to active state
   } else {
      // hold the job in a queued state and query the dbs again in 10 
      // seconds
   }
})

Is this possible?



via deeveeABC

No comments:

Post a Comment