Do not log response statistics at sending issues
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index 36d694e761de04b901b5c2c3353069c4bebaaf07..809c623ab51062db24812fefac5f780be76e63ab 100644 (file)
@@ -1,6 +1,6 @@
 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
 
-import { ChargingStationWorkerData, WorkerMessage, WorkerMessageEvents } from '../types/Worker';
+import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
 
 import Configuration from '../utils/Configuration';
 import { Storage } from '../performance/storage/Storage';
@@ -18,9 +18,9 @@ export default class Bootstrap {
   private static workerImplementation: WorkerAbstract | null = null;
   private static storage: Storage;
   private static numberOfChargingStations: number;
-  private version: string = version;
+  private readonly version: string = version;
   private started: boolean;
-  private workerScript: string;
+  private readonly workerScript: string;
 
   private constructor() {
     this.started = false;
@@ -72,6 +72,8 @@ export default class Bootstrap {
       } catch (error) {
         console.error(chalk.red('Bootstrap start error '), error);
       }
+    } else {
+      console.error(chalk.red('Cannot start an already started charging stations simulator'));
     }
   }
 
@@ -79,6 +81,8 @@ export default class Bootstrap {
     if (isMainThread && this.started) {
       await Bootstrap.workerImplementation.stop();
       await Bootstrap.storage.close();
+    } else {
+      console.error(chalk.red('Trying to stop the charging stations simulator while not started'));
     }
     this.started = false;
   }
@@ -99,8 +103,8 @@ export default class Bootstrap {
         poolOptions: {
           workerChoiceStrategy: Configuration.getWorkerPoolStrategy()
         },
-        messageHandler: async (msg: WorkerMessage) => {
-          if (msg.id === WorkerMessageEvents.PERFORMANCE_STATISTICS) {
+        messageHandler: async (msg: ChargingStationWorkerMessage) => {
+          if (msg.id === ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS) {
             await Bootstrap.storage.storePerformanceStatistics(msg.data);
           }
         }