From 88c8135d9c477c7d1777c84f982c880f026f3ec5 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Thu, 30 Jan 2020 13:25:52 +0100 Subject: [PATCH] refactor(core/engine): make serviceMonitor a module group `Engine`s internal `coreComponents()` API sets up a bunch of things like a `ProcessManager` and the `ServiceMonitor`. The `ServiceMonitor` activates itself on `embark:engine:started` and practically monitors registered services until the process has been explicitly stopped. There are some commands that don't actually need service monitoring like `build` and a future `exec` command that's in the making. For those cases it's useful to have them disable the service monitor when `coreComponents()` is used. This commit moves the `ServiceMonitor` instantiation out of `coreComponents()` and introduces a new module group instead. This then lets commands that need service monitoring instantiate it explicitly. --- packages/core/engine/src/index.ts | 21 ++++++++++++--------- packages/embark/src/cmd/cmd_controller.js | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/core/engine/src/index.ts b/packages/core/engine/src/index.ts index 11b1eee41..d60ec364f 100644 --- a/packages/core/engine/src/index.ts +++ b/packages/core/engine/src/index.ts @@ -155,6 +155,7 @@ export class Engine { blockchain: this.blockchainComponents, coreComponents: this.coreComponents, stackComponents: this.stackComponents, + serviceMonitor: this.serviceMonitor, consoleComponents: this.consoleComponents, blockchainStackComponents: this.blockchainStackComponents, compiler: this.compilerComponents, @@ -196,15 +197,7 @@ export class Engine { }); } - coreComponents() { - - // TODO: should be made into a component - this.processManager = new ProcessManager({ - events: this.events, - logger: this.logger, - plugins: this.plugins - }); - + serviceMonitor(options) { this.servicesMonitor = new ServicesMonitor({ events: this.events, logger: this.logger, plugins: this.plugins }); if (this.servicesMonitor) { @@ -220,6 +213,16 @@ export class Engine { }); } } + } + + coreComponents(options) { + + // TODO: should be made into a component + this.processManager = new ProcessManager({ + events: this.events, + logger: this.logger, + plugins: this.plugins + }); this.registerModulePackage('embark-code-runner', { ipc: this.ipc }); diff --git a/packages/embark/src/cmd/cmd_controller.js b/packages/embark/src/cmd/cmd_controller.js index 4315245ea..8cd90946c 100644 --- a/packages/embark/src/cmd/cmd_controller.js +++ b/packages/embark/src/cmd/cmd_controller.js @@ -61,6 +61,7 @@ class EmbarkController { Object.assign(engine.config.blockchainConfig, { isStandalone: true }); engine.registerModuleGroup("coreComponents"); + engine.registerModuleGroup("serviceMonitor"); engine.registerModuleGroup("blockchainStackComponents"); engine.registerModuleGroup("blockchain"); @@ -160,6 +161,7 @@ class EmbarkController { function (callback) { engine.registerModuleGroup("coreComponents"); + engine.registerModuleGroup("serviceMonitor"); engine.registerModuleGroup("stackComponents"); engine.registerModuleGroup("consoleComponents"); @@ -375,6 +377,7 @@ class EmbarkController { }, callback => { engine.registerModuleGroup("coreComponents"); + engine.registerModuleGroup("serviceMonitor"); engine.registerModuleGroup("stackComponents"); engine.registerModuleGroup("consoleComponents");