What is the best way to continuously process items added to the queue? I see the following method
queue.process
https://github.com/Automattic/kue#processing-jobs
but this will process and return. Items added after this call are obviously not processed.
I thought to do:
queue.on('job enqueue', function(id, type){
queue.process('email', function (job, done) {
console.log('processing one: ' + job.id);
done(null);
});
});
But not sure if this fires multiple process methods ignoring the current queue status?
EDIT:
I have created a handler to listen to the 'email' type, yet it is only called once given the scenario below. Unless I am missing something, I would expect process to be run exactly 10 times here?
const queue = kue.createQueue();
queue.process('email', function (job, done) {
email(job.id, job.data, done);
});
var email = function(id, email, done) {
console.log('job: %s, sent to: %s number: %s', id, email.to, email.number);
done(null, {result: 'OK'});
};
queue
.on('job enqueue', function (id, type) {
console.log('job %s got queued of type %s with id %s', id, type);
})
.on('job complete', function (id, result) {
console.log('job complete: ' + id);
});
for (var i = 0; i < 10; i++) {
queue
.create('email', {
title: 'welcome email for tj',
number: i,
to: 'tj@learnboost.com',
template: 'welcome-email'
})
.removeOnComplete(true)
.save();
}