refactor: factor out charging profiles preparation
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationWorker.ts
index db7ae2cb4462ff79f50359dc989b50536a73edd6..7c7a523558bd6e9b547afe8775ec71c79f11187b 100644 (file)
@@ -6,9 +6,10 @@ import { parentPort } from 'node:worker_threads';
 import { ThreadWorker } from 'poolifier';
 
 import { ChargingStation } from './ChargingStation';
+import { BaseError } from '../exception';
 import type { ChargingStationWorkerData } from '../types';
 import { Configuration } from '../utils';
-import { WorkerConstants, type WorkerMessage, WorkerMessageEvents } from '../worker';
+import { POOL_MAX_INACTIVE_TIME, type WorkerMessage, WorkerMessageEvents } from '../worker';
 
 const moduleName = 'ChargingStationWorker';
 
@@ -48,7 +49,7 @@ class ChargingStationWorker extends AsyncResource {
           }
           break;
         default:
-          throw new Error(
+          throw new BaseError(
             `Unknown worker event: '${message.event}' received with data: '${JSON.stringify(
               message.data,
               null,
@@ -63,7 +64,7 @@ class ChargingStationWorker extends AsyncResource {
 export let chargingStationWorker: ChargingStationWorker | ThreadWorker<ChargingStationWorkerData>;
 if (Configuration.workerPoolInUse()) {
   chargingStationWorker = new ThreadWorker<ChargingStationWorkerData>(startChargingStation, {
-    maxInactiveTime: WorkerConstants.POOL_MAX_INACTIVE_TIME,
+    maxInactiveTime: POOL_MAX_INACTIVE_TIME,
   });
 } else {
   chargingStationWorker = new ChargingStationWorker();