2015-12-16 22:57:58 +08:00
|
|
|
'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;
|
2015-12-24 00:29:11 +08:00
|
|
|
this.metadataBackend.redisCmd(this.db, 'RPOP', [ this.queueName ], function (err, job_id) {
|
2015-12-16 22:57:58 +08:00
|
|
|
if (err) {
|
|
|
|
return self.emit('error', err);
|
|
|
|
}
|
|
|
|
|
2015-12-24 00:29:11 +08:00
|
|
|
self.push(job_id);
|
2015-12-16 22:57:58 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = JobQueueConsumer;
|