mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-03 01:13:55 +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.checkList = {};
|
||||||
this.checkTimers = {};
|
this.checkTimers = {};
|
||||||
this.checkState = {};
|
this.checkState = {};
|
||||||
|
this.working = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.addCheck = function(name, checkFn, time) {
|
ServicesMonitor.prototype.initCheck = function(checkName) {
|
||||||
this.logger.info('add check: ' + name);
|
var self = this;
|
||||||
this.checkList[name] = {fn: checkFn, interval: time || 5000};
|
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) {
|
ServicesMonitor.prototype.stopCheck = function(name) {
|
||||||
@ -21,26 +51,12 @@ ServicesMonitor.prototype.stopCheck = function(name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.startMonitor = function() {
|
ServicesMonitor.prototype.startMonitor = function() {
|
||||||
this.logger.info('startMonitor');
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
this.working = true;
|
||||||
|
this.logger.trace('startMonitor');
|
||||||
|
|
||||||
async.eachObject(this.checkList, function(checkName, check, callback) {
|
async.eachObject(this.checkList, function(checkName, check, callback) {
|
||||||
self.events.on('check:' + checkName, function(obj) {
|
self.initCheck(checkName);
|
||||||
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);
|
|
||||||
});
|
|
||||||
callback();
|
callback();
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user