From 447f96706123cea2ebe71473d34e2cc4cc18a568 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 16 Mar 2017 07:31:52 -0400 Subject: [PATCH] add service check functionality to plugin api --- lib/core/engine.js | 9 +++++++++ lib/core/plugin.js | 6 ++++++ test_app/embark.json | 3 ++- test_app/extensions/embark-service/index.js | 5 +++++ test_app/extensions/embark-service/package.json | 11 +++++++++++ test_app/package.json | 1 + 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test_app/extensions/embark-service/index.js create mode 100644 test_app/extensions/embark-service/package.json diff --git a/lib/core/engine.js b/lib/core/engine.js index 856593d55..9f7a87361 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -37,6 +37,15 @@ Engine.prototype.init = function(_options) { }; Engine.prototype.startMonitor = function() { + var self = this; + if (this.plugins) { + var 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(); }; diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 9d6ff37ac..45a498f07 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -17,6 +17,7 @@ var Plugin = function(options) { this.contractsConfigs = []; this.contractsFiles = []; this.compilers = []; + this.serviceChecks = []; this.pluginTypes = []; this.logger = options.logger; this.events = options.events; @@ -98,6 +99,11 @@ Plugin.prototype.registerConsoleCommand = function(cb) { this.pluginTypes.push('console'); }; +Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) { + this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time}); + this.pluginTypes.push('serviceChecks'); +}; + Plugin.prototype.has = function(pluginType) { return this.pluginTypes.indexOf(pluginType) >= 0; }; diff --git a/test_app/embark.json b/test_app/embark.json index 5cdaae975..0dd46dd19 100644 --- a/test_app/embark.json +++ b/test_app/embark.json @@ -14,6 +14,7 @@ "buildDir": "dist/", "config": "config/", "plugins": { - "embark-babel": {"files": ["**/*.js", "**/*.jsx", "!**/_vendor/*.js"]} + "embark-babel": {"files": ["**/*.js", "**/*.jsx", "!**/_vendor/*.js"]}, + "embark-service": {} } } diff --git a/test_app/extensions/embark-service/index.js b/test_app/extensions/embark-service/index.js new file mode 100644 index 000000000..27f58c84e --- /dev/null +++ b/test_app/extensions/embark-service/index.js @@ -0,0 +1,5 @@ +module.exports = function(embark) { + embark.registerServiceCheck('PluginService', function(cb) { + cb({name: "ServiceName", status: "green"}); + }); +}; diff --git a/test_app/extensions/embark-service/package.json b/test_app/extensions/embark-service/package.json new file mode 100644 index 000000000..b20033a19 --- /dev/null +++ b/test_app/extensions/embark-service/package.json @@ -0,0 +1,11 @@ +{ + "name": "embark-service", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/test_app/package.json b/test_app/package.json index 042f454f1..d1ea282a1 100644 --- a/test_app/package.json +++ b/test_app/package.json @@ -15,6 +15,7 @@ }, "dependencies": { "embark-babel": "^1.0.0", + "embark-service": "./extensions/embark-service", "ethereumjs-testrpc": "^3.0.3" } }