mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-22 13:19:06 +00:00
if monitor is already running then init service
This commit is contained in:
parent
5cf287a747
commit
8d8ff671f7
@ -6,11 +6,41 @@ var ServicesMonitor = function(options) {
|
||||
this.checkList = {};
|
||||
this.checkTimers = {};
|
||||
this.checkState = {};
|
||||
this.working = false;
|
||||
};
|
||||
|
||||
ServicesMonitor.prototype.addCheck = function(name, checkFn, time) {
|
||||
this.logger.info('add check: ' + name);
|
||||
this.checkList[name] = {fn: checkFn, interval: time || 5000};
|
||||
ServicesMonitor.prototype.initCheck = function(checkName) {
|
||||
var self = this;
|
||||
var check = this.checkList[checkName];
|
||||
|
||||
if (!check) { return false; }
|
||||
|
||||
self.events.on('check:' + checkName, function(obj) {
|
||||
self.checkState[checkName] = obj.name[obj.status];
|
||||
self.events.emit("servicesState", self.checkState);
|
||||
});
|
||||
|
||||
if (check.interval !== 0) {
|
||||
self.checkTimers[checkName] = setInterval(function() {
|
||||
check.fn.call(check.fn, function(obj) {
|
||||
self.events.emit('check:' + checkName, obj);
|
||||
});
|
||||
}, check.interval);
|
||||
}
|
||||
|
||||
check.fn.call(check.fn, function(obj) {
|
||||
self.events.emit('check:' + checkName, obj);
|
||||
});
|
||||
};
|
||||
|
||||
ServicesMonitor.prototype.addCheck = function(checkName, checkFn, time) {
|
||||
var self = this;
|
||||
this.logger.trace('add check: ' + checkName);
|
||||
this.checkList[checkName] = {fn: checkFn, interval: time || 5000};
|
||||
|
||||
if (this.working) {
|
||||
this.initCheck(checkName);
|
||||
}
|
||||
};
|
||||
|
||||
ServicesMonitor.prototype.stopCheck = function(name) {
|
||||
@ -21,26 +51,12 @@ ServicesMonitor.prototype.stopCheck = function(name) {
|
||||
};
|
||||
|
||||
ServicesMonitor.prototype.startMonitor = function() {
|
||||
this.logger.info('startMonitor');
|
||||
var self = this;
|
||||
this.working = true;
|
||||
this.logger.trace('startMonitor');
|
||||
|
||||
async.eachObject(this.checkList, function(checkName, check, callback) {
|
||||
self.events.on('check:' + checkName, function(obj) {
|
||||
self.checkState[checkName] = obj.name[obj.status];
|
||||
self.events.emit("servicesState", self.checkState);
|
||||
});
|
||||
|
||||
if (check.interval !== 0) {
|
||||
self.checkTimers[checkName] = setInterval(function() {
|
||||
check.fn.call(check.fn, function(obj) {
|
||||
self.events.emit('check:' + checkName, obj);
|
||||
});
|
||||
}, check.interval);
|
||||
}
|
||||
|
||||
check.fn.call(check.fn, function(obj) {
|
||||
self.events.emit('check:' + checkName, obj);
|
||||
});
|
||||
self.initCheck(checkName);
|
||||
callback();
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user