disque-eventemitter
v0.3.1
Published
EventEmitter wrapper for Disque GetJob
Downloads
5
Maintainers
Readme
disque-eventemitter
EventEmitter to simplify disque GETJOB
Features
- EventEmitter pattern for GETJOB
- job event emitted for each job
- Supports pause/resume of emitter
Installation
$ npm install disque-eventemitter --save
Usage
'use strict';
var DisqueEventEmitter = require('disque-eventemitter');
console.info('Listening for jobs Ctrl-C to end');
var de = new DisqueEventEmitter({host:'127.0.0.1', port: 7711}, 'test', {concurrency: 2});
de.on('error', function(err) {
console.error(err);
});
de.on('job', function(job, done) {
console.info(job);
de.ack(job, function() {
// Indicate we are done and to ack the job
setTimeout(function(){
done();
}, 5000 * Math.random());
});
});
Documentation
new DisqueEventEmitter(disqueConfig, queueName, options)
Sets up the instance of disque to connect to and the queue to use
Arguments
disqueConfig
- Config hash that is passed straight through to disque. Example: {'host':'127.0.0.1', 'port': 7711}queueName
- Name of queue to get jobs fromoptions
- Optionsconcurrency
- Number of jobs to emit in parallel. Defaults to 1jobCount
- Number of jobs to get at once. Defaults to 1. If you get more than one job at a time all will be emitted and may exceed concurrency limit.withCounters
- Get jobs with counters showing nacks and additional deliveries
ack(job, callback)
Removes job from queue. If you don't ack a job it will keep reappearing in emitted events.
nack(job, callback)
Immediately returns job back to queue. Job will be re-emitted.
pause()
Pauses emitting jobs. Jobs may still be emitted from the previous scan operation.
resume()
Resumes a paused emitter.
job event
.on('job', function(job, done){})
When the job event is raised the callback receives two arguments: the job, and a completion callback. You must call the completion callback when done to prevent stalling the EventEmitter
People
The author is Chris Kinsman from PushSpring