refactor services monitor to use events instead of passing addCheck around
This commit is contained in:
parent
0804779a20
commit
37d54e22db
|
@ -18,7 +18,6 @@ class Blockchain {
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
this.locale = options.locale;
|
this.locale = options.locale;
|
||||||
this.isDev = options.isDev;
|
this.isDev = options.isDev;
|
||||||
this.addCheck = options.addCheck;
|
|
||||||
this.web3Endpoint = '';
|
this.web3Endpoint = '';
|
||||||
this.isWeb3Ready = false;
|
this.isWeb3Ready = false;
|
||||||
this.web3StartedInProcess = false;
|
this.web3StartedInProcess = false;
|
||||||
|
@ -111,7 +110,7 @@ class Blockchain {
|
||||||
const self = this;
|
const self = this;
|
||||||
const NO_NODE = 'noNode';
|
const NO_NODE = 'noNode';
|
||||||
|
|
||||||
this.addCheck('Ethereum', function (cb) {
|
this.events.request("services:register", 'Ethereum', function (cb) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function checkNodeConnection(next) {
|
function checkNodeConnection(next) {
|
||||||
self.assertNodeConnection(true, (err) => {
|
self.assertNodeConnection(true, (err) => {
|
||||||
|
|
|
@ -40,11 +40,6 @@ class Engine {
|
||||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||||
this.plugins = this.config.plugins;
|
this.plugins = this.config.plugins;
|
||||||
|
|
||||||
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
|
|
||||||
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
|
||||||
return cb({name: 'Embark ' + self.version, status: 'on'});
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
if (this.interceptLogs || this.interceptLogs === undefined) {
|
if (this.interceptLogs || this.interceptLogs === undefined) {
|
||||||
this.doInterceptLogs();
|
this.doInterceptLogs();
|
||||||
}
|
}
|
||||||
|
@ -77,18 +72,11 @@ class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
startMonitor() {
|
startMonitor() {
|
||||||
let self = this;
|
const self = this;
|
||||||
if (this.plugins) {
|
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins});
|
||||||
// --------
|
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
||||||
// TODO: this only works for services done on startup
|
return cb({name: 'Embark ' + self.version, status: 'on'});
|
||||||
// --------
|
}, 0);
|
||||||
let servicePlugins = this.plugins.getPluginsFor('serviceChecks');
|
|
||||||
servicePlugins.forEach(function (plugin) {
|
|
||||||
plugin.serviceChecks.forEach(function (pluginCheck) {
|
|
||||||
self.servicesMonitor.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.servicesMonitor.startMonitor();
|
this.servicesMonitor.startMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,9 +245,7 @@ class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
webServerService() {
|
webServerService() {
|
||||||
this.registerModule('webserver', {
|
this.registerModule('webserver');
|
||||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storageService(_options) {
|
storageService(_options) {
|
||||||
|
@ -281,7 +267,6 @@ class Engine {
|
||||||
this.blockchain = new Blockchain({
|
this.blockchain = new Blockchain({
|
||||||
contractsConfig: this.config.contractsConfig,
|
contractsConfig: this.config.contractsConfig,
|
||||||
blockchainConfig: this.config.blockchainConfig,
|
blockchainConfig: this.config.blockchainConfig,
|
||||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
|
||||||
events: this.events,
|
events: this.events,
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
isDev: this.isDev,
|
isDev: this.isDev,
|
||||||
|
@ -290,7 +275,6 @@ class Engine {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.registerModule('whisper', {
|
this.registerModule('whisper', {
|
||||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
|
||||||
// TODO: this should not be needed and should be deducted from the config instead
|
// TODO: this should not be needed and should be deducted from the config instead
|
||||||
// the eth provider is not necessary the same as the whisper one
|
// the eth provider is not necessary the same as the whisper one
|
||||||
web3: this.blockchain.web3
|
web3: this.blockchain.web3
|
||||||
|
|
|
@ -2,12 +2,18 @@ let async = require('../utils/async_extend.js');
|
||||||
|
|
||||||
class ServicesMonitor {
|
class ServicesMonitor {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
const self = this;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
|
this.plugins = options.plugins;
|
||||||
this.checkList = {};
|
this.checkList = {};
|
||||||
this.checkTimers = {};
|
this.checkTimers = {};
|
||||||
this.checkState = {};
|
this.checkState = {};
|
||||||
this.working = false;
|
this.working = false;
|
||||||
|
|
||||||
|
self.events.setCommandHandler("services:register", (checkName, checkFn, time) => {
|
||||||
|
self.addCheck(checkName, checkFn, time);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +71,11 @@ ServicesMonitor.prototype.startMonitor = function () {
|
||||||
this.working = true;
|
this.working = true;
|
||||||
this.logger.trace('startMonitor');
|
this.logger.trace('startMonitor');
|
||||||
|
|
||||||
|
let servicePlugins = this.plugins.getPluginsProperty('serviceChecks', 'serviceChecks');
|
||||||
|
servicePlugins.forEach(function (pluginCheck) {
|
||||||
|
self.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time);
|
||||||
|
});
|
||||||
|
|
||||||
async.eachObject(this.checkList, function (checkName, check, callback) {
|
async.eachObject(this.checkList, function (checkName, check, callback) {
|
||||||
self.initCheck(checkName);
|
self.initCheck(checkName);
|
||||||
callback();
|
callback();
|
||||||
|
|
|
@ -300,6 +300,7 @@ class Embark {
|
||||||
|
|
||||||
function startServices(callback) {
|
function startServices(callback) {
|
||||||
|
|
||||||
|
engine.startMonitor();
|
||||||
engine.startService("libraryManager");
|
engine.startService("libraryManager");
|
||||||
engine.startService("codeRunner");
|
engine.startService("codeRunner");
|
||||||
engine.startService("web3");
|
engine.startService("web3");
|
||||||
|
@ -307,7 +308,6 @@ class Embark {
|
||||||
engine.startService("deployment");
|
engine.startService("deployment");
|
||||||
engine.startService("storage");
|
engine.startService("storage");
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
engine.startMonitor();
|
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function setupStoragePlugin(callback){
|
function setupStoragePlugin(callback){
|
||||||
|
|
|
@ -10,11 +10,10 @@ class IPFS {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
this.storageConfig = options.storageConfig;
|
this.storageConfig = embark.config.storageConfig;
|
||||||
this.host = options.host || this.storageConfig.upload.host;
|
this.host = options.host || this.storageConfig.upload.host;
|
||||||
this.port = options.port || this.storageConfig.upload.port;
|
this.port = options.port || this.storageConfig.upload.port;
|
||||||
this.protocol = options.protocol || this.storageConfig.upload.protocol;
|
this.protocol = options.protocol || this.storageConfig.upload.protocol;
|
||||||
this.addCheck = options.addCheck;
|
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +47,7 @@ class IPFS {
|
||||||
self.logger.info(__('IPFS node is offline') + '..');
|
self.logger.info(__('IPFS node is offline') + '..');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!self.addCheck) {
|
self.events.request("services:register", 'IPFS', function (cb) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addCheck('IPFS', function (cb) {
|
|
||||||
self.logger.trace("Checking IPFS version...");
|
self.logger.trace("Checking IPFS version...");
|
||||||
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
|
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
|
||||||
if(self.protocol !== 'https'){
|
if(self.protocol !== 'https'){
|
||||||
|
|
|
@ -7,7 +7,6 @@ class SpecialConfigs {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
this.addCheck = options.addCheck;
|
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.contractsConfig = embark.config.contractsConfig;
|
this.contractsConfig = embark.config.contractsConfig;
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ class Swarm {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
this.storageConfig = options.storageConfig;
|
this.storageConfig = embark.config.storageConfig;
|
||||||
this.addCheck = options.addCheck;
|
this.host = options.host || this.storageConfig.host;
|
||||||
|
this.port = options.port || this.storageConfig.port;
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
|
|
||||||
this.providerUrl = utils.buildUrl(options.protocol || options.storageConfig.upload.protocol, options.host || options.storageConfig.upload.host, options.port || options.storageConfig.upload.port);
|
this.providerUrl = utils.buildUrl(options.protocol || options.storageConfig.upload.protocol, options.host || options.storageConfig.upload.host, options.port || options.storageConfig.upload.port);
|
||||||
|
@ -32,7 +33,6 @@ class Swarm {
|
||||||
this.embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
|
this.embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
|
@ -53,12 +53,7 @@ class Swarm {
|
||||||
self.logger.info(__('Swarm node is offline...'));
|
self.logger.info(__('Swarm node is offline...'));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.addCheck) {
|
self.events.request("services:register", 'Swarm', function(cb){
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add check for console
|
|
||||||
this.addCheck('Swarm', function(cb){
|
|
||||||
self.logger.trace("Checking Swarm availability...");
|
self.logger.trace("Checking Swarm availability...");
|
||||||
self.bzz.isAvailable().then(result => {
|
self.bzz.isAvailable().then(result => {
|
||||||
return cb({name: "Swarm ", status: result ? 'on':'off'});
|
return cb({name: "Swarm ", status: result ? 'on':'off'});
|
||||||
|
|
|
@ -7,7 +7,6 @@ class WebServer {
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.addCheck = options.addCheck;
|
|
||||||
this.webServerConfig = embark.config.webServerConfig;
|
this.webServerConfig = embark.config.webServerConfig;
|
||||||
if (!this.webServerConfig.enabled) {
|
if (!this.webServerConfig.enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -29,8 +28,7 @@ class WebServer {
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
let url = 'http://' + this.host + ':' + this.port;
|
let url = 'http://' + this.host + ':' + this.port;
|
||||||
|
|
||||||
//embark.registerServiceCheck('WebserverService', function (cb) {
|
this.events.request("services:register", 'Webserver', function (cb) {
|
||||||
this.addCheck('Webserver', function (cb) {
|
|
||||||
utils.checkIsAvailable(url, function (available) {
|
utils.checkIsAvailable(url, function (available) {
|
||||||
let devServer = __('Webserver') + ' (' + url + ')';
|
let devServer = __('Webserver') + ' (' + url + ')';
|
||||||
let serverStatus = (available ? 'on' : 'off');
|
let serverStatus = (available ? 'on' : 'off');
|
||||||
|
|
|
@ -8,7 +8,6 @@ class Whisper {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.communicationConfig = embark.config.communicationConfig;
|
this.communicationConfig = embark.config.communicationConfig;
|
||||||
this.addCheck = options.addCheck;
|
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ class Whisper {
|
||||||
|
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
const self = this;
|
const self = this;
|
||||||
self.addCheck('Whisper', function (cb) {
|
self.events.request("services:register", 'Whisper', function (cb) {
|
||||||
if (!self.web3.currentProvider || self.web3.currentProvider.connection.readyState !== 1) {
|
if (!self.web3.currentProvider || self.web3.currentProvider.connection.readyState !== 1) {
|
||||||
return self.connectToProvider();
|
return self.connectToProvider();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue