X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=27f4a6073c8c5159c1bfa2b134688e6d6027325a;hb=e6a332330734dcd91f2619880d2006392cae67e5;hp=ac1dd88c64b22871644a9cca2597c32678d8075d;hpb=847c5243ac4d0d01c1f5d2d363a494fa686f6d73;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index ac1dd88c..27f4a607 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -8,7 +8,7 @@ import { isMainThread } from 'node:worker_threads'; import chalk from 'chalk'; import { availableParallelism } from 'poolifier'; -import { waitChargingStationEvents } from './ChargingStationUtils'; +import { waitChargingStationEvents } from './Helpers'; import type { AbstractUIServer } from './ui-server/AbstractUIServer'; import { UIServerFactory } from './ui-server/UIServerFactory'; import { version } from '../../package.json' assert { type: 'json' }; @@ -109,7 +109,7 @@ export class Bootstrap extends EventEmitter { public async start(): Promise { if (!isMainThread) { - throw new Error('Cannot start charging stations simulator from worker thread'); + throw new BaseError('Cannot start charging stations simulator from worker thread'); } if (this.started === false) { if (this.starting === false) { @@ -176,7 +176,7 @@ export class Bootstrap extends EventEmitter { public async stop(): Promise { if (!isMainThread) { - throw new Error('Cannot stop charging stations simulator from worker thread'); + throw new BaseError('Cannot stop charging stations simulator from worker thread'); } if (this.started === true) { if (this.stopping === false) { @@ -230,7 +230,7 @@ export class Bootstrap extends EventEmitter { if (workerConfiguration?.elementsPerWorker === 'auto') { elementsPerWorker = this.numberOfChargingStations > availableParallelism() - ? Math.round(this.numberOfChargingStations / availableParallelism()) + ? Math.round(this.numberOfChargingStations / (availableParallelism() * 1.5)) : 1; } this.workerImplementation === null && @@ -281,9 +281,20 @@ export class Bootstrap extends EventEmitter { msg.data as Statistics, ); break; + case ChargingStationWorkerMessageEvents.startWorkerElementError: + logger.error( + `${this.logPrefix()} ${moduleName}.messageHandler: Error occured while starting worker element:`, + msg.data, + ); + this.emit(ChargingStationWorkerMessageEvents.startWorkerElementError, msg.data); + break; + case ChargingStationWorkerMessageEvents.startedWorkerElement: + break; default: throw new BaseError( - `Unknown event type: '${msg.event}' for data: ${JSON.stringify(msg.data, null, 2)}`, + `Unknown charging station worker event: '${ + msg.event + }' received with data: ${JSON.stringify(msg.data, null, 2)}`, ); } } catch (error) {