fix: disable dynamic reload until spurious file change is identified
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index c6a5278edccc1b5f9e324fff5584f32c3e042fde..bd3fb81283b079f66ceed55b380434666c331613 100644 (file)
@@ -149,7 +149,7 @@ import {
   roundTo,
   secureRandom,
   sleep,
-  watchJsonFile,
+  // watchJsonFile,
 } from '../utils';
 
 export class ChargingStation {
@@ -664,44 +664,55 @@ export class ChargingStation {
         }
         this.openWSConnection();
         // Monitor charging station template file
-        this.templateFileWatcher = watchJsonFile(
-          this.templateFile,
-          FileType.ChargingStationTemplate,
-          this.logPrefix(),
-          undefined,
-          (event, filename): void => {
-            if (isNotEmptyString(filename) && event === 'change') {
-              try {
-                logger.debug(
-                  `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
-                    this.templateFile
-                  } file have changed, reload`,
-                );
-                this.sharedLRUCache.deleteChargingStationTemplate(this.templateFileHash);
-                // Initialize
-                this.initialize();
-                this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!);
-                // Restart the ATG
-                this.stopAutomaticTransactionGenerator();
-                delete this.automaticTransactionGeneratorConfiguration;
-                if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
-                  this.startAutomaticTransactionGenerator();
-                }
-                if (this.getEnableStatistics() === true) {
-                  this.performanceStatistics?.restart();
-                } else {
-                  this.performanceStatistics?.stop();
-                }
-                // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
-              } catch (error) {
-                logger.error(
-                  `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
-                  error,
-                );
-              }
-            }
-          },
-        );
+        // FIXME: Disabled until the spurious configuration file change detection is identified
+        // this.templateFileWatcher = watchJsonFile(
+        //   this.templateFile,
+        //   FileType.ChargingStationTemplate,
+        //   this.logPrefix(),
+        //   undefined,
+        //   (event, filename): void => {
+        //     if (isNotEmptyString(filename) && event === 'change') {
+        //       try {
+        //         logger.debug(
+        //           `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
+        //             this.templateFile
+        //           } file have changed, reload`,
+        //         );
+        //         this.sharedLRUCache.deleteChargingStationTemplate(this.templateFileHash);
+        //         // Initialize
+        //         this.initialize();
+        //         this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!);
+        //         // Restart the ATG
+        //         this.stopAutomaticTransactionGenerator()
+        //           .then(() => {
+        //             delete this.automaticTransactionGeneratorConfiguration;
+        //             if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
+        //               this.startAutomaticTransactionGenerator();
+        //             }
+        //           })
+        //           .catch((err) =>
+        //             logger.error(
+        //               `${this.logPrefix()} failed to stop ATG at ${
+        //                 FileType.ChargingStationTemplate
+        //               } reload`,
+        //               err,
+        //             ),
+        //           );
+        //         if (this.getEnableStatistics() === true) {
+        //           this.performanceStatistics?.restart();
+        //         } else {
+        //           this.performanceStatistics?.stop();
+        //         }
+        //         // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
+        //       } catch (error) {
+        //         logger.error(
+        //           `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
+        //           error,
+        //         );
+        //       }
+        //     }
+        //   },
+        // );
         this.started = true;
         parentPort?.postMessage(buildStartedMessage(this));
         this.starting = false;
@@ -873,13 +884,13 @@ export class ChargingStation {
     parentPort?.postMessage(buildUpdatedMessage(this));
   }
 
-  public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
+  public async stopAutomaticTransactionGenerator(connectorIds?: number[]): Promise<void> {
     if (isNotEmptyArray(connectorIds)) {
       for (const connectorId of connectorIds!) {
-        this.automaticTransactionGenerator?.stopConnector(connectorId);
+        await this.automaticTransactionGenerator?.stopConnector(connectorId);
       }
     } else {
-      this.automaticTransactionGenerator?.stop();
+      await this.automaticTransactionGenerator?.stop();
     }
     this.saveAutomaticTransactionGeneratorConfiguration();
     parentPort?.postMessage(buildUpdatedMessage(this));
@@ -2171,7 +2182,7 @@ export class ChargingStation {
     this.stopHeartbeat();
     // Stop ongoing transactions
     if (this.automaticTransactionGenerator?.started === true) {
-      this.stopAutomaticTransactionGenerator();
+      await this.stopAutomaticTransactionGenerator();
     } else {
       await this.stopRunningTransactions(reason);
     }
@@ -2318,7 +2329,7 @@ export class ChargingStation {
     this.stopHeartbeat();
     // Stop the ATG if needed
     if (this.getAutomaticTransactionGeneratorConfiguration().stopOnConnectionFailure === true) {
-      this.stopAutomaticTransactionGenerator();
+      await this.stopAutomaticTransactionGenerator();
     }
     if (
       this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries()! ||