CartoDB-SQL-API/batch/pubsub/job-publisher.js
2016-10-11 18:30:35 +02:00

34 lines
834 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) {
self.pool.release(DB, client);
if (err) {
return error('Error publishing to ' + self.channel + ':' + host + ', ' + err.message);
}
debug('publish to ' + self.channel + ':' + host);
});
});
};
module.exports = JobPublisher;