CartoDB-SQL-API/batch/pubsub/job-publisher.js

34 lines
834 B
JavaScript
Raw Normal View History

'use strict';
2016-10-12 00:28:46 +08:00
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) {
2016-10-12 00:30:35 +08:00
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;