From 6fee1791db82bd4605b180612fe642a7e2c4caa0 Mon Sep 17 00:00:00 2001 From: HazbinFaulted Date: Mon, 25 Apr 2022 14:16:07 +0200 Subject: [PATCH] fixed empty list response to LIST_CHARGING_STATIONS --- src/charging-station/Bootstrap.ts | 11 ++++------- .../ui-websocket-services/AbstractUIService.ts | 2 -- src/worker/WorkerFactory.ts | 6 +++--- src/worker/WorkerSet.ts | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 725105ce..18e934db 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -34,18 +34,17 @@ export default class Bootstrap { private constructor() { this.started = false; this.workerScript = path.join( - // wouldn't path.resolve(./ChargingStationWorker.js) faster & simpler ? - path.resolve(__dirname, '../'), + path.resolve(__dirname, '../'), // wouldn't path.resolve(./ChargingStationWorker.js) achieve the same result ? 'charging-station', 'ChargingStationWorker.js' ); - this.initWorkerImplementation(); // init thread - Configuration.getUIWebSocketServer().enabled && // create webSocket + this.initWorkerImplementation(); + Configuration.getUIWebSocketServer().enabled && (this.uiWebSocketServer = new UIWebSocketServer({ ...Configuration.getUIWebSocketServer().options, handleProtocols: UIServiceUtils.handleProtocols, })); - Configuration.getPerformanceStorage().enabled && // create storage ??? but for what + Configuration.getPerformanceStorage().enabled && (this.storage = StorageFactory.getStorage( Configuration.getPerformanceStorage().type, Configuration.getPerformanceStorage().uri, @@ -152,10 +151,8 @@ export default class Bootstrap { workerChoiceStrategy: Configuration.getWorkerPoolStrategy(), }, messageHandler: async (msg: ChargingStationWorkerMessage) => { - console.log('initWorkerImplementation: messageHandler: ', msg); if (msg.id === ChargingStationWorkerMessageEvents.STARTED) { this.uiWebSocketServer.chargingStations.add(msg.data.id as string); - console.log(this.uiWebSocketServer.chargingStations); } else if (msg.id === ChargingStationWorkerMessageEvents.STOPPED) { this.uiWebSocketServer.chargingStations.delete(msg.data.id as string); } else if (msg.id === ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS) { diff --git a/src/charging-station/ui-websocket-services/AbstractUIService.ts b/src/charging-station/ui-websocket-services/AbstractUIService.ts index 6755cd6e..42cfa428 100644 --- a/src/charging-station/ui-websocket-services/AbstractUIService.ts +++ b/src/charging-station/ui-websocket-services/AbstractUIService.ts @@ -42,12 +42,10 @@ export default abstract class AbstractUIService { } protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string { - console.log(JSON.stringify([command, payload])); // DEBUG return JSON.stringify([command, payload]); } private handleListChargingStations(): string[] { - // FIXED return Array.from(this.uiWebSocketServer.chargingStations); } } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 7e69fc56..70bcc386 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -21,9 +21,9 @@ export default class WorkerFactory { if (!isMainThread) { throw new Error('Trying to get a worker implementation outside the main thread'); } - workerOptions = workerOptions ?? ({} as WorkerOptions); // why not default parameter ? + workerOptions = workerOptions ?? ({} as WorkerOptions); workerOptions.workerStartDelay = - workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; // why null safety ? + workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; workerOptions.elementStartDelay = workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY; workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions); @@ -31,7 +31,7 @@ export default class WorkerFactory { // eslint-disable-next-line @typescript-eslint/no-misused-promises (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler); console.log('before'); - let workerImplementation: WorkerAbstract = null; // enabling strictNullChecks would be safer ? + let workerImplementation: WorkerAbstract = null; console.log(workerImplementation); switch (workerProcessType) { case WorkerProcessType.WORKER_SET: diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 782284f3..6e890902 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -54,7 +54,7 @@ export default class WorkerSet extends WorkerAbstract { id: WorkerMessageEvents.START_WORKER_ELEMENT, data: elementData, }); - this.getLastWorkerSetElement().numberOfWorkerElements++; // should there not be a hanshake to be safer ? + this.getLastWorkerSetElement().numberOfWorkerElements++; // Start element sequentially to optimize memory at startup if (this.workerOptions.elementStartDelay > 0) { await Utils.sleep(this.workerOptions.elementStartDelay); -- 2.34.1