fix(simulator): ensure configuration file reload will restart the
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 7 Nov 2023 21:57:25 +0000 (22:57 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 7 Nov 2023 21:57:25 +0000 (22:57 +0100)
simulator

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/utils/Configuration.ts

index 4e848c1f29adcb9f88eb6f5a90ea0a6e93ea972a..465d5bf21f98b29d9d410914d6d0a0226f560ce9 100644 (file)
@@ -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<void> {
+  public async stop(waitChargingStationsStopped = true): Promise<void> {
     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<string>((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<string>((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<void> {
-    await this.stop();
+  public async restart(waitChargingStationsStopped?: boolean): Promise<void> {
+    await this.stop(waitChargingStationsStopped);
     await this.start();
   }
 
index d994422b07bf91e176fd7d36bc680318fadabc4c..48b4897f9e4cd44cb43b95c71702bc6de5386598 100644 (file)
@@ -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)) {