Reputation: 5230
I am implementing redis queue with Kue in my nodejs app. I have an API which will add email jobs
to an email queue
. Is it a good practice to have a cron job listening to the redis
email queue
for new jobs or is there a way by which an event is fired from the node.js
app when a new email job
is entered and caught from a separate node.js
app to process it. I'm a little confused on the right approach.
Upvotes: 0
Views: 364
Reputation: 7560
First, there are good events supplied by Kue:
https://github.com/Automattic/kue#queue-events
queue.on('job enqueue', function(id, type){
console.log( 'Job %s got queued of type %s', id, type );
});
However, it seems from your question that you don't only want to be notified of jobs in the queue but instead you want to process these jobs as they are enqueued.
https://github.com/Automattic/kue#processing-jobs
queue.process('email', function(job, done){
// do something with job.data
// callback to done
email(job.data.to, done);
});
Upvotes: 1