CartoDB-SQL-API/batch/job_queue_consumer.js
2015-12-21 19:57:10 +01:00

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;