fix: fix elementsPerWorker automatic calculation
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Jul 2023 14:29:03 +0000 (16:29 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Jul 2023 14:29:03 +0000 (16:29 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts

index 96e7b8ceb2bc30523e2bad399d0a0a0776911d45..1550f6a7dc8ee92547fda280dbe4f569592f753e 100644 (file)
@@ -212,12 +212,12 @@ export class Bootstrap extends EventEmitter {
   }
 
   private initializeWorkerImplementation(): void {
-    let elementsPerWorker = WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER;
-    if (
-      Configuration.getWorker()?.elementsPerWorker === 'auto' &&
-      this.numberOfChargingStations > availableParallelism()
-    ) {
-      elementsPerWorker = Math.round(this.numberOfChargingStations / availableParallelism());
+    let elementsPerWorker: number;
+    if (Configuration.getWorker()?.elementsPerWorker === 'auto') {
+      elementsPerWorker =
+        this.numberOfChargingStations > availableParallelism()
+          ? Math.round(this.numberOfChargingStations / availableParallelism())
+          : 1;
     }
     this.workerImplementation === null &&
       (this.workerImplementation = WorkerFactory.getWorkerImplementation<ChargingStationWorkerData>(
@@ -228,7 +228,8 @@ export class Bootstrap extends EventEmitter {
           elementStartDelay: Configuration.getWorker().elementStartDelay,
           poolMaxSize: Configuration.getWorker().poolMaxSize,
           poolMinSize: Configuration.getWorker().poolMinSize,
-          elementsPerWorker,
+          elementsPerWorker:
+            elementsPerWorker ?? (Configuration.getWorker().elementsPerWorker as number),
           poolOptions: {
             workerChoiceStrategy: Configuration.getWorker().poolStrategy,
             messageHandler: this.messageHandler.bind(this) as (message: unknown) => void,