From: HazbinFaulted Date: Mon, 25 Apr 2022 12:04:46 +0000 (+0200) Subject: fixe X-Git-Tag: v1.1.59~22^2^2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a0239c1fdb0cebc4807aa2e381e7232cfe0e127c;p=e-mobility-charging-stations-simulator.git fixe --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index d39c705c..725105ce 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -34,17 +34,18 @@ export default class Bootstrap { private constructor() { this.started = false; this.workerScript = path.join( + // wouldn't path.resolve(./ChargingStationWorker.js) faster & simpler ? path.resolve(__dirname, '../'), 'charging-station', 'ChargingStationWorker.js' ); - this.initWorkerImplementation(); - Configuration.getUIWebSocketServer().enabled && + this.initWorkerImplementation(); // init thread + Configuration.getUIWebSocketServer().enabled && // create webSocket (this.uiWebSocketServer = new UIWebSocketServer({ ...Configuration.getUIWebSocketServer().options, handleProtocols: UIServiceUtils.handleProtocols, })); - Configuration.getPerformanceStorage().enabled && + Configuration.getPerformanceStorage().enabled && // create storage ??? but for what (this.storage = StorageFactory.getStorage( Configuration.getPerformanceStorage().type, Configuration.getPerformanceStorage().uri, @@ -151,8 +152,10 @@ 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 680a73eb..6755cd6e 100644 --- a/src/charging-station/ui-websocket-services/AbstractUIService.ts +++ b/src/charging-station/ui-websocket-services/AbstractUIService.ts @@ -42,10 +42,12 @@ 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(): Set { - return this.uiWebSocketServer.chargingStations; + private handleListChargingStations(): string[] { + // FIXED + return Array.from(this.uiWebSocketServer.chargingStations); } } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index b297f42b..7e69fc56 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -21,16 +21,18 @@ export default class WorkerFactory { if (!isMainThread) { throw new Error('Trying to get a worker implementation outside the main thread'); } - workerOptions = workerOptions ?? ({} as WorkerOptions); + workerOptions = workerOptions ?? ({} as WorkerOptions); // why not default parameter ? workerOptions.workerStartDelay = - workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; + workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; // why null safety ? workerOptions.elementStartDelay = workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY; workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions); workerOptions?.messageHandler && // eslint-disable-next-line @typescript-eslint/no-misused-promises (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler); - let workerImplementation: WorkerAbstract = null; + console.log('before'); + let workerImplementation: WorkerAbstract = null; // enabling strictNullChecks would be safer ? + console.log(workerImplementation); switch (workerProcessType) { case WorkerProcessType.WORKER_SET: workerOptions.elementsPerWorker = diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 6e890902..782284f3 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++; + this.getLastWorkerSetElement().numberOfWorkerElements++; // should there not be a hanshake to be safer ? // Start element sequentially to optimize memory at startup if (this.workerOptions.elementStartDelay > 0) { await Utils.sleep(this.workerOptions.elementStartDelay);