Burstable
Simple and powerful task queue for Node.js on top of Beanstalkd
Features
- Wait for job completion
- Child jobs (keeping parent alive till done)
How-To
Setup
import Burstable from 'burstable';
const burstable = new Burstable(
host,
port,
{
log: function(level, err|message, meta) {
winston.log(level, message.message || message, meta);
}
}
);
Spawning jobs
burstable.spawn(tube, {
delay: 0,
priority: 1000,
timeout: 10 * 60 * 1000,
payload: {
},
wait: Job | [Job...] | [{tube: String, id: Number}]
});
Handling jobs
burstable.handle(tube, function (payload) {
return Promise.resolve();
return Promise.reject();
return this.child(anotherTube);
this.log('info', 'doing the thing');
}, {
maxTries: 3,
backoff: {
initial: 60 * 1000,
exponential: 1.5
},
log: function(level, err|message, meta) {
winston.log(level, message.message || message, meta);
}
});
burstable.start();
Dynamic tubes
Lets you dynamically update tube names for a handler.
Useful if you have jobs triggered by users and you want jobs to run seqentually per user but in parallel overall (so no one blocks eachother).
burstable.handle(async function () {
let users = await db.user.findAll();
return users.map(user => {
return `media.process.${user.id}`
});
}, async function (payload) {
}, {
});
When spawning simply construct the tubename with the appropriate values:
burstable.spawn(`media.process.${user.id}`, {
payload: {}
});
Keep in mind that burstable will spawn a connection equal to width * amount of tubes. You'll want to make sure that your server is configured to handle that amount of connections (ulimit).
Debugging
Use DEBUG=burstable*
to enable verbose debugging.