fix: fix worker configuration merge issue
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 19 Mar 2024 17:50:20 +0000 (18:50 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 19 Mar 2024 17:50:20 +0000 (18:50 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/worker/WorkerFactory.ts

index 6eacfff46c462655a10a84d5209f545424694701..64953a9687a8f730a233ce7517ffa1f2842bbd3c 100644 (file)
@@ -366,7 +366,9 @@ export class Bootstrap extends EventEmitter {
         elementsPerWorker,
         poolOptions: {
           messageHandler: this.messageHandler.bind(this) as MessageHandler<Worker>,
-          workerOptions: { resourceLimits: workerConfiguration.resourceLimits }
+          ...(workerConfiguration.resourceLimits != null && {
+            workerOptions: { resourceLimits: workerConfiguration.resourceLimits }
+          })
         }
       }
     )
index 29aedcbae2bbb1ee7ee66b23432c27359483cf66..92b5fe753a34efceb03334364a0a67b2aa44e91c 100644 (file)
@@ -1244,7 +1244,7 @@ export class ChargingStation extends EventEmitter {
       stationInfoFromFile.templateHash === stationInfoFromTemplate.templateHash
     ) {
       return setChargingStationOptions(
-        { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromFile },
+        mergeDeepRight(Constants.DEFAULT_STATION_INFO, stationInfoFromFile),
         options
       )
     }
@@ -1255,7 +1255,7 @@ export class ChargingStation extends EventEmitter {
         stationInfoFromTemplate
       )
     return setChargingStationOptions(
-      { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromTemplate },
+      mergeDeepRight(Constants.DEFAULT_STATION_INFO, stationInfoFromTemplate),
       options
     )
   }
index 833c939f1767e832b021f152a5d2725caf221f72..67da00d88a5b2d32572fa2f8a5f422fe3b73a843 100644 (file)
@@ -1,5 +1,7 @@
 import { isMainThread } from 'node:worker_threads'
 
+import { mergeDeepRight } from 'rambda'
+
 import type { WorkerAbstract } from './WorkerAbstract.js'
 import { DEFAULT_WORKER_OPTIONS } from './WorkerConstants.js'
 import { WorkerDynamicPool } from './WorkerDynamicPool.js'
@@ -21,7 +23,7 @@ export class WorkerFactory {
     if (!isMainThread) {
       throw new Error('Cannot get a worker implementation outside the main thread')
     }
-    workerOptions = { ...DEFAULT_WORKER_OPTIONS, ...workerOptions }
+    workerOptions = mergeDeepRight<WorkerOptions>(DEFAULT_WORKER_OPTIONS, workerOptions ?? {})
     let workerImplementation: WorkerAbstract<T>
     switch (workerProcessType) {
       case WorkerProcessType.workerSet: