From 44fccdf0fe511a528780feb1213bb1049d76be05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 5 Feb 2024 22:48:30 +0100 Subject: [PATCH] refactor: cleanup worker events handling in main thread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 2c1b0f43..75accffc 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -150,6 +150,15 @@ export class Bootstrap extends EventEmitter { ChargingStationWorkerMessageEvents.performanceStatistics, this.workerEventPerformanceStatistics ) + this.on( + ChargingStationWorkerMessageEvents.workerElementError, + (msg: ChargingStationWorkerMessage) => { + logger.error( + `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${msg.data.event}' event on worker:`, + msg.data + ) + } + ) this.initializeCounters() const workerConfiguration = Configuration.getConfigurationSection( ConfigurationSection.worker @@ -338,30 +347,23 @@ export class Bootstrap extends EventEmitter { try { switch (msg.event) { case ChargingStationWorkerMessageEvents.added: - this.emit(ChargingStationWorkerMessageEvents.added, msg.data as ChargingStationData) + this.emit(ChargingStationWorkerMessageEvents.added, msg.data) break case ChargingStationWorkerMessageEvents.started: - this.emit(ChargingStationWorkerMessageEvents.started, msg.data as ChargingStationData) + this.emit(ChargingStationWorkerMessageEvents.started, msg.data) break case ChargingStationWorkerMessageEvents.stopped: - this.emit(ChargingStationWorkerMessageEvents.stopped, msg.data as ChargingStationData) + this.emit(ChargingStationWorkerMessageEvents.stopped, msg.data) break case ChargingStationWorkerMessageEvents.updated: - this.emit(ChargingStationWorkerMessageEvents.updated, msg.data as ChargingStationData) + this.emit(ChargingStationWorkerMessageEvents.updated, msg.data) break case ChargingStationWorkerMessageEvents.performanceStatistics: - this.emit( - ChargingStationWorkerMessageEvents.performanceStatistics, - msg.data as Statistics - ) + this.emit(ChargingStationWorkerMessageEvents.performanceStatistics, msg.data) break case ChargingStationWorkerMessageEvents.addedWorkerElement: break case ChargingStationWorkerMessageEvents.workerElementError: - logger.error( - `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${(msg.data as ChargingStationWorkerEventError).event}' event on worker:`, - msg.data - ) this.emit(ChargingStationWorkerMessageEvents.workerElementError, msg.data) break default: -- 2.34.1