detect when ethereum node comes back online and redeploy

This commit is contained in:
Iuri Matias 2017-03-11 12:27:10 -05:00
parent 8d8ff671f7
commit 54420b327e
2 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,8 @@
var async = require('../utils/async_extend.js'); var async = require('../utils/async_extend.js');
// TODO: need to separate colors from states
// i.e use status: /on|off|warn/ not /red|green/
// it's up to the logger or console to determine the color
var ServicesMonitor = function(options) { var ServicesMonitor = function(options) {
this.events = options.events; this.events = options.events;
this.logger = options.logger; this.logger = options.logger;
@ -16,7 +19,15 @@ ServicesMonitor.prototype.initCheck = function(checkName) {
if (!check) { return false; } if (!check) { return false; }
self.events.on('check:' + checkName, function(obj) { self.events.on('check:' + checkName, function(obj) {
// TODO: see todo above
if (check && check.status === 'red' && obj.status === 'green') {
self.events.emit('check:backOnline:' + checkName);
}
if (check && check.status === 'green' && obj.status === 'red') {
self.events.emit('check:wentOffline:' + checkName);
}
self.checkState[checkName] = obj.name[obj.status]; self.checkState[checkName] = obj.name[obj.status];
check.status = obj.status;
self.events.emit("servicesState", self.checkState); self.events.emit("servicesState", self.checkState);
}); });

View File

@ -103,12 +103,21 @@ var Embark = {
engine.logger.info("loaded plugins: " + pluginList.join(", ")); engine.logger.info("loaded plugins: " + pluginList.join(", "));
} }
engine.startMonitor();
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("abi"); engine.startService("abi");
engine.startService("deployment"); engine.startService("deployment");
engine.startService("ipfs"); engine.startService("ipfs");
engine.events.on('check:backOnline:Ethereum', function() {
engine.logger.info('Ethereum node detected..');
engine.config.reloadConfig();
engine.deployManager.deployContracts(function() {
engine.logger.info('Deployment Done');
});
});
engine.deployManager.deployContracts(function() { engine.deployManager.deployContracts(function() {
engine.startService("fileWatcher"); engine.startService("fileWatcher");
if (options.runWebserver) { if (options.runWebserver) {
@ -117,7 +126,6 @@ var Embark = {
port: options.serverPort port: options.serverPort
}); });
} }
engine.startMonitor();
callback(); callback();
}); });
} }