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
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
function JobPublisher(pool) {
|
|
|
|
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;
|
|
|
|
|
2016-10-12 00:41:59 +08:00
|
|
|
this.pool.acquire(Channel.DB, function (err, client) {
|
2016-07-07 16:44:17 +08:00
|
|
|
if (err) {
|
2016-07-07 20:14:46 +08:00
|
|
|
return error('Error adquiring redis client: ' + err.message);
|
2016-07-07 16:44:17 +08:00
|
|
|
}
|
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
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
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
if (err) {
|
2016-10-13 03:32:29 +08:00
|
|
|
return error('Error publishing to ' + Channel.NAME + ':' + user + ', ' + err.message);
|
2016-07-07 20:14:46 +08:00
|
|
|
}
|
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
debug('publish to ' + Channel.NAME + ':' + user);
|
2016-07-07 20:14:46 +08:00
|
|
|
});
|
2016-07-07 16:44:17 +08:00
|
|
|
});
|
2015-12-16 22:57:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = JobPublisher;
|