2015-12-16 22:57:58 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-23 02:31:25 +08:00
|
|
|
function JobSubscriber(redis) {
|
2015-12-29 22:46:04 +08:00
|
|
|
this.channel = 'batch:hosts';
|
2015-12-16 22:57:58 +08:00
|
|
|
this.client = redis.createClient(global.settings.redis_port, global.settings.redis_host);
|
|
|
|
}
|
|
|
|
|
|
|
|
JobSubscriber.prototype.subscribe = function (onMessage) {
|
|
|
|
this.client.subscribe(this.channel);
|
|
|
|
this.client.on('message', onMessage);
|
|
|
|
};
|
|
|
|
|
2015-12-23 03:12:10 +08:00
|
|
|
JobSubscriber.prototype.unsubscribe = function () {
|
|
|
|
this.client.unsubscribe(this.channel);
|
|
|
|
};
|
|
|
|
|
2015-12-16 22:57:58 +08:00
|
|
|
module.exports = JobSubscriber;
|