CartoDB-SQL-API/batch/job_publisher.js
2016-07-07 14:14:46 +02:00

33 lines
827 B
JavaScript

'use strict';
var debug = require('./util/debug')('pubsub:publisher');
var error = require('./util/debug')('pubsub:publisher:error');
var DB = 0;
function JobPublisher(pool) {
this.pool = pool;
this.channel = 'batch:hosts';
}
JobPublisher.prototype.publish = function (host) {
var self = this;
this.pool.acquire(DB, function (err, client) {
if (err) {
return error('Error adquiring redis client: ' + err.message);
}
client.publish(self.channel, host, function (err) {
if (err) {
return error('Error publishing to ' + self.channel + ':' + host + ', ' + err.message);
}
debug('publish to ' + self.channel + ':' + host);
self.pool.release(DB, client);
});
});
};
module.exports = JobPublisher;