2015-12-16 22:57:58 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var redis = require('redis');
|
|
|
|
|
|
|
|
function JobSubscriber() {
|
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;
|