Move some status attributes at constructor begin
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 10 Sep 2022 04:11:50 +0000 (06:11 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 10 Sep 2022 04:11:50 +0000 (06:11 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts

index 706a4b8d900ccaa327d5811dc91d8587b9a640ce..a09ee7a1019b82759b1ed134d2bd5733b4601e20 100644 (file)
@@ -35,11 +35,11 @@ export default class AutomaticTransactionGenerator {
     automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration,
     chargingStation: ChargingStation
   ) {
+    this.started = false;
     this.configuration = automaticTransactionGeneratorConfiguration;
     this.chargingStation = chargingStation;
     this.connectorsStatus = new Map<number, Status>();
     this.stopConnectors();
-    this.started = false;
   }
 
   public static getInstance(
index 37cd1e64d2693ae99436137aebe32df5a7cfe46e..d0c4016291c699c1433104f9448a5670cf5e7e41 100644 (file)
@@ -35,7 +35,7 @@ const noChargingStationTemplatesExitCode = 2;
 
 export class Bootstrap {
   private static instance: Bootstrap | null = null;
-  private workerImplementation: WorkerAbstract<ChargingStationWorkerData> | null = null;
+  private workerImplementation: WorkerAbstract<ChargingStationWorkerData> | null;
   private readonly uiServer!: AbstractUIServer;
   private readonly storage!: Storage;
   private numberOfChargingStationTemplates!: number;
@@ -47,6 +47,7 @@ export class Bootstrap {
 
   private constructor() {
     this.started = false;
+    this.workerImplementation = null;
     this.workerScript = path.join(
       path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
       'charging-station',
index bbb5c6f290a39503092b9537e27b9a2ac8535123..0775bcb93252de952589738be028c6c398979e4c 100644 (file)
@@ -114,6 +114,9 @@ export default class ChargingStation {
   private readonly chargingStationWorkerBroadcastChannel: ChargingStationWorkerBroadcastChannel;
 
   constructor(index: number, templateFile: string) {
+    this.started = false;
+    this.wsConnectionRestarted = false;
+    this.autoReconnectRetryCount = 0;
     this.index = index;
     this.templateFile = templateFile;
     this.connectors = new Map<number, ConnectorStatus>();
@@ -122,9 +125,6 @@ export default class ChargingStation {
     this.sharedLRUCache = SharedLRUCache.getInstance();
     this.authorizedTagsCache = AuthorizedTagsCache.getInstance();
     this.chargingStationWorkerBroadcastChannel = new ChargingStationWorkerBroadcastChannel(this);
-    this.started = false;
-    this.wsConnectionRestarted = false;
-    this.autoReconnectRetryCount = 0;
 
     this.initialize();
   }
@@ -1361,16 +1361,15 @@ export default class ChargingStation {
       if (this.isRegistered()) {
         if (this.isInAcceptedState()) {
           await this.startMessageSequence();
-          this.wsConnectionRestarted && this.flushMessageBuffer();
         }
       } else {
         logger.error(
           `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`
         );
       }
-      this.started === false && (this.started = true);
-      this.autoReconnectRetryCount = 0;
       this.wsConnectionRestarted = false;
+      this.autoReconnectRetryCount = 0;
+      this.started = true;
       parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
     } else {
       logger.warn(
@@ -1398,7 +1397,7 @@ export default class ChargingStation {
             code
           )}' and reason '${reason}'`
         );
-        await this.reconnect(code);
+        await this.reconnect();
         break;
     }
     parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
@@ -1814,6 +1813,7 @@ export default class ChargingStation {
     if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) {
       this.startAutomaticTransactionGenerator();
     }
+    this.wsConnectionRestarted === true && this.flushMessageBuffer();
   }
 
   private async stopMessageSequence(
@@ -1966,7 +1966,7 @@ export default class ChargingStation {
       : false;
   }
 
-  private async reconnect(code: number): Promise<void> {
+  private async reconnect(): Promise<void> {
     // Stop WebSocket ping
     this.stopWebSocketPing();
     // Stop heartbeat