From: Jérôme Benoit Date: Wed, 17 Mar 2021 22:30:17 +0000 (+0100) Subject: Avoid circular modules import X-Git-Tag: v1.0.1-0~86 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e57acf6acb996f5fbc5790a2a4fc17248f8319db;p=e-mobility-charging-stations-simulator.git Avoid circular modules import Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 6770f7bb..f47a879b 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -15,6 +15,7 @@ export default class Bootstrap { private constructor() { this.started = false; this.workerScript = path.join(path.resolve(__dirname, '../'), 'charging-station', 'StationWorker.js'); + Configuration.setConfigurationChangeCallback(async () => this.restart()); } public static getInstance(): Bootstrap { diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 99519b7d..552fab21 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -1,6 +1,5 @@ import ConfigurationData, { StationTemplateURL } from '../types/ConfigurationData'; -import Bootstrap from '../charging-station/Bootstrap'; import { WorkerProcessType } from '../types/Worker'; import fs from 'fs'; import path from 'path'; @@ -9,6 +8,11 @@ export default class Configuration { private static configurationFilePath = path.join(path.resolve(__dirname, '../'), 'assets', 'config.json'); private static configurationFileWatcher: fs.FSWatcher; private static configuration: ConfigurationData; + private static configurationChangeCallback: () => Promise; + + static setConfigurationChangeCallback(cb: () => Promise): void { + Configuration.configurationChangeCallback = cb; + } static getStatisticsDisplayInterval(): number { // Read conf @@ -122,7 +126,9 @@ export default class Configuration { return fs.watch(Configuration.configurationFilePath).on('change', async (e): Promise => { // Nullify to force configuration file reading Configuration.configuration = null; - await Bootstrap.getInstance().restart(); + if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) { + await Configuration.configurationChangeCallback(); + } }); }