2015-12-16 22:57:58 +08:00
|
|
|
'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');
|
2016-07-07 16:44:17 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function JobPublisher (pool) {
|
2016-07-07 20:14:46 +08:00
|
|
|
this.pool = pool;
|
2015-12-16 22:57:58 +08:00
|
|
|
}
|
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
JobPublisher.prototype.publish = function (user) {
|
2016-07-07 16:44:17 +08:00
|
|
|
var self = this;
|
|
|
|
|
2020-05-18 17:32:41 +08:00
|
|
|
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));
|
2015-12-16 22:57:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = JobPublisher;
|