From: Jérôme Benoit Date: Tue, 7 Nov 2023 21:57:25 +0000 (+0100) Subject: fix(simulator): ensure configuration file reload will restart the X-Git-Tag: v1.2.24~37 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ab7a96fac9432c4759e0bb69a12bb481b1570e02;p=e-mobility-charging-stations-simulator.git fix(simulator): ensure configuration file reload will restart the simulator Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 4e848c1f..465d5bf2 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -99,7 +99,7 @@ export class Bootstrap extends EventEmitter { performanceStorageConfiguration.uri!, this.logPrefix(), )); - Configuration.configurationChangeCallback = async () => Bootstrap.getInstance().restart(); + Configuration.configurationChangeCallback = async () => Bootstrap.getInstance().restart(false); } public static getInstance(): Bootstrap { @@ -173,7 +173,7 @@ export class Bootstrap extends EventEmitter { } } - public async stop(): Promise { + public async stop(waitChargingStationsStopped = true): Promise { if (this.started === true) { if (this.stopping === false) { this.stopping = true; @@ -184,22 +184,24 @@ export class Bootstrap extends EventEmitter { Constants.EMPTY_FROZEN_OBJECT, ), ); - await Promise.race([ - waitChargingStationEvents( - this, - ChargingStationWorkerMessageEvents.stopped, - this.numberOfChargingStations, - ), - new Promise((resolve) => { - setTimeout(() => { - const message = `Timeout ${formatDurationMilliSeconds( - Constants.STOP_SIMULATOR_TIMEOUT, - )} reached at stopping charging stations simulator`; - console.warn(chalk.yellow(message)); - resolve(message); - }, Constants.STOP_SIMULATOR_TIMEOUT); - }), - ]); + if (waitChargingStationsStopped === true) { + await Promise.race([ + waitChargingStationEvents( + this, + ChargingStationWorkerMessageEvents.stopped, + this.numberOfChargingStations, + ), + new Promise((resolve) => { + setTimeout(() => { + const message = `Timeout ${formatDurationMilliSeconds( + Constants.STOP_SIMULATOR_TIMEOUT, + )} reached at stopping charging stations simulator`; + console.warn(chalk.yellow(message)); + resolve(message); + }, Constants.STOP_SIMULATOR_TIMEOUT); + }), + ]); + } await this.workerImplementation?.stop(); this.workerImplementation = null; this.uiServer?.stop(); @@ -216,8 +218,8 @@ export class Bootstrap extends EventEmitter { } } - public async restart(): Promise { - await this.stop(); + public async restart(waitChargingStationsStopped?: boolean): Promise { + await this.stop(waitChargingStationsStopped); await this.start(); } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index d994422b..48b4897f 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -547,6 +547,11 @@ export class Configuration { try { return watch(Configuration.configurationFile, (event, filename): void => { if (filename!.trim()!.length > 0 && event === 'change') { + console.warn( + `${chalk.green(configurationLogPrefix())} ${chalk.yellow( + `${FileType.Configuration} ${this.configurationFile} file have changed, reload`, + )}`, + ); delete Configuration.configurationData; Configuration.configurationSectionCache.clear(); if (!isUndefined(Configuration.configurationChangeCallback)) {