29 lines
680 B
JavaScript
29 lines
680 B
JavaScript
'use strict';
|
|
|
|
var util = require('util');
|
|
var Readable = require('stream').Readable;
|
|
|
|
function JobQueueConsumer(metadataBackend, host) {
|
|
Readable.call(this, {
|
|
encoding: 'utf8',
|
|
objectMode: true
|
|
});
|
|
this.db = 5;
|
|
this.queueName = 'queue:' + host;
|
|
this.metadataBackend = metadataBackend;
|
|
}
|
|
util.inherits(JobQueueConsumer, Readable);
|
|
|
|
JobQueueConsumer.prototype._read = function () {
|
|
var self = this;
|
|
this.metadataBackend.redisCmd(this.db, 'RPOP', [ this.queueName ], function (err, jobId) {
|
|
if (err) {
|
|
return self.emit('error', err);
|
|
}
|
|
|
|
self.push(jobId);
|
|
});
|
|
};
|
|
|
|
module.exports = JobQueueConsumer;
|