app.js
var TaskQue = require('../lib/TaskQue.js').TaskQue,
que1 = new TaskQue('app1');
que1.task('email', { address: '[email protected]' }).save();
que1.task('email', { address: '[email protected]' }).save();
que1.task('email', { address: '[email protected]' }).save();
que1.task('pdf', { name: 'pdf1' }).save();
que1.task('pdf', { name: 'pdf2' }).save();
que1.task('pdf', { name: 'pdf3' }).save(function (err) {
que1.end();
});
worker10.js - 10 tasks
var TaskQue = require('../lib/TaskQue.js').TaskQue,
que1 = new TaskQue('app1');
function pdfHandler(tasks) {
console.log('APP1: PDFs: ' + tasks.length);
(function next(task) {
if (task) {
console.log('APP1: Get PDF: %s', task.data.name);
setTimeout(function () {
task.done(function (err) {
console.log('APP1: done PDF: %s', task.data.name);
next(tasks.shift());
});
}, 1000);
}
}(tasks.shift()));
}
que1.process('pdf', { count: 10 }, pdfHandler);
worker1.js - 1 task
var TaskQue = require('../lib/TaskQue.js').TaskQue,
que1 = new TaskQue('app1');
function handler(task) {
console.log('APP1: get email: ' + task.data.address);
setTimeout(function () {
task.done(function (err) {
console.log('APP1: done email: %s - error: %s', task.data.address, err);
});
}, 500);
}
que1.process('email', handler);