Beanstalkd Worker for node
Features
- Wait for job completion
- Child jobs (keeping parent alive till done)
How-To
Setup
npm install --save beanstalkd-worker
import BeanstalkdWorker from 'beanstalkd-worker';
const worker = new BeanstalkdWorker(
host,
port,
);
Spawning jobs
worker.spawn(tube, {
}, {
delay: 0,
priority: 1000,
timeout: 10 * 60 * 1000
}).then(function (job) {
console.log(job.id);
});
Handling jobs
worker.handle(tube, function (payload) {
return Promise.resolve();
return Promise.reject();
this.spawn(someTub);
this.touch();
await this.child(anotherTube, {});
await this.wait(anotherTube, jobId);
return this.delay(5000);
}, {
tries: 3,
backoff: {
initial: 60 * 1000,
exponential: 1.5
}
});
worker.start();
Keep in mind that worker 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=beanstalkd-worker*
to enable verbose debugging.