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

32 lines
1023 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');
2019-12-24 01:19:08 +08:00
function JobPublisher (pool) {
this.pool = pool;
}
JobPublisher.prototype.publish = function (user) {
var self = this;
this.pool.acquire(Channel.DB)
.then(client => {
client.publish(Channel.NAME, user, function (err) {
self.pool.release(Channel.DB, client)
.then(() => {
if (err) {
return error('Error publishing to ' + Channel.NAME + ':' + user + ', ' + err.message);
}
debug('publish to ' + Channel.NAME + ':' + user);
})
.catch(err => error('Error releasing redis client: ' + err.message));
});
})
.catch(err => error('Error adquiring redis client: ' + err.message));
};
module.exports = JobPublisher;