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

32 lines
839 B
JavaScript
Raw Normal View History

'use strict';
2016-10-12 00:41:59 +08:00
var Channel = require('./channel');
2016-10-12 00:28:46 +08:00
var debug = require('./../util/debug')('pubsub:publisher');
var error = require('./../util/debug')('pubsub:publisher:error');
function JobPublisher(pool) {
this.pool = pool;
}
JobPublisher.prototype.publish = function (user) {
var self = this;
2016-10-12 00:41:59 +08:00
this.pool.acquire(Channel.DB, function (err, client) {
if (err) {
return error('Error adquiring redis client: ' + err.message);
}
client.publish(Channel.NAME, user, function (err) {
2016-10-12 00:41:59 +08:00
self.pool.release(Channel.DB, client);
2016-10-12 00:30:35 +08:00
if (err) {
return error('Error publishing to ' + Channel.NAME + ':' + user + ', ' + err.message);
}
debug('publish to ' + Channel.NAME + ':' + user);
});
});
};
module.exports = JobPublisher;