nodejs Kue job processing logic

5.2k views Asked by At

I have a very simple logical question.

I will be running job processing logic on a separate app server.

My job processing app will be a standalone app, doing nothing just processing jobs.

In my code, how do I make sure that my app continuously keep checking redis server for jobs ? -Do I need to run the code in infinite loop ? -or Do I need to keep restarting my app

or there is some inbuilt mechanism in Kue that I'm missing here ?

Thanks

1

There are 1 answers

0
Alex On BEST ANSWER

See the documentation - https://github.com/Automattic/kue#processing-jobs

While there is a queue, it will continually run, and pick off jobs.

As per the example:

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

queue.process('email', function(job, done){
  email(job.data.to, done);
});

function email(address, done) {
  if(!isValidEmail(address)) {
    //done('invalid to address') is possible but discouraged
    return done(new Error('invalid to address'));
  }
  // email send stuff...
  done();
}