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.spawn(someTub);
return this.child(anotherTube);
return this.delay(5000);
this.log('info', 'doing the thing');
}, {
maxTries: 3,
backoff: {
initial: 60 * 1000,
exponential: 1.5
},
labels: function(payload) {
return {
accountId: payload.accountId
};
},
log: function(level, err|message, meta) {
winston.log(level, message.message || message, meta);
}
});
burstable.start();
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.