refactor(simulator): remove unneeded duplicate initialization at startup
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index 113a9f1dae77e389a79a88b8367a5349088f8f7c..7a823e56f3ed7f253db079fbf8482d188528ecf4 100644 (file)
@@ -49,6 +49,9 @@ export class Bootstrap {
   private readonly workerScript: string;
 
   private constructor() {
+    // Enable unconditionally for now
+    this.logUnhandledRejection();
+    this.logUncaughtException();
     this.started = false;
     this.workerImplementation = null;
     this.workerScript = path.join(
@@ -56,7 +59,6 @@ export class Bootstrap {
       'charging-station',
       `ChargingStationWorker${path.extname(fileURLToPath(import.meta.url))}`
     );
-    this.initialize();
     Configuration.getUIServer().enabled === true &&
       (this.uiServer = UIServerFactory.getUIServerImplementation(Configuration.getUIServer()));
     Configuration.getPerformanceStorage().enabled === true &&
@@ -78,10 +80,8 @@ export class Bootstrap {
   public async start(): Promise<void> {
     if (isMainThread && this.started === false) {
       try {
-        // Enable unconditionally for now
-        this.logUnhandledRejection();
-        this.logUncaughtException();
-        this.initialize();
+        this.initializeCounters();
+        this.initializeWorkerImplementation();
         await this.storage?.open();
         await this.workerImplementation?.start();
         this.uiServer?.start();
@@ -144,7 +144,6 @@ export class Bootstrap {
 
   public async restart(): Promise<void> {
     await this.stop();
-    this.initialize();
     await this.start();
   }
 
@@ -238,7 +237,7 @@ export class Bootstrap {
     this.storage.storePerformanceStatistics(data) as void;
   };
 
-  private initialize() {
+  private initializeCounters() {
     this.numberOfChargingStationTemplates = 0;
     this.numberOfChargingStations = 0;
     const stationTemplateUrls = Configuration.getStationTemplateUrls();
@@ -258,7 +257,6 @@ export class Bootstrap {
       process.exit(exitCodes.noChargingStationTemplates);
     }
     this.numberOfStartedChargingStations = 0;
-    this.initializeWorkerImplementation();
   }
 
   private logUncaughtException(): void {