Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs Kue job processing logic

Tags:

node.js

redis

kue

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

like image 772
pkpk Avatar asked Nov 01 '22 02:11

pkpk


1 Answers

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();
}
like image 200
Alex Avatar answered Nov 18 '22 10:11

Alex