X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=329c5546dcde0a255add2c4a136652d2b337cc61;hb=8bd02502e5cb44f91964241a5bc93b762ca7557e;hp=7c80067ccd93905b2e76cec7ac9a3641bd670ff6;hpb=48d17ce2fd55a8b0d49d80263f3ffd16bcfe89b0;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 7c80067c..329c5546 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -2,7 +2,7 @@ import path from 'path'; import { fileURLToPath } from 'url'; -import { isMainThread } from 'worker_threads'; +import { type Worker, isMainThread } from 'worker_threads'; import chalk from 'chalk'; @@ -30,8 +30,10 @@ import UIServerFactory from './ui-server/UIServerFactory'; const moduleName = 'Bootstrap'; -const missingChargingStationsConfigurationExitCode = 1; -const noChargingStationTemplatesExitCode = 2; +enum exitCodes { + missingChargingStationsConfiguration = 1, + noChargingStationTemplates = 2, +} export class Bootstrap { private static instance: Bootstrap | null = null; @@ -107,13 +109,13 @@ export class Bootstrap { console.warn( chalk.yellow("'stationTemplateUrls' not defined or empty in configuration, exiting") ); - process.exit(missingChargingStationsConfigurationExitCode); + process.exit(exitCodes.missingChargingStationsConfiguration); } if (this.numberOfChargingStations === 0) { console.warn( chalk.yellow('No charging station template enabled in configuration, exiting') ); - process.exit(noChargingStationTemplatesExitCode); + process.exit(exitCodes.noChargingStationTemplates); } else { console.info( chalk.green( @@ -177,6 +179,7 @@ export class Bootstrap { workerChoiceStrategy: Configuration.getWorker().poolStrategy, }, messageHandler: this.messageHandler.bind(this) as ( + this: Worker, msg: ChargingStationWorkerMessage ) => void, } @@ -225,11 +228,25 @@ export class Bootstrap { private workerEventStarted = (data: ChargingStationData) => { this.uiServer?.chargingStations.set(data.stationInfo.hashId, data); ++this.numberOfStartedChargingStations; + logger.info( + `${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${ + data.stationInfo.chargingStationId + } (hashId: ${data.stationInfo.hashId}) started (${ + this.numberOfStartedChargingStations + } started from ${this.numberOfChargingStations})` + ); }; private workerEventStopped = (data: ChargingStationData) => { this.uiServer?.chargingStations.set(data.stationInfo.hashId, data); --this.numberOfStartedChargingStations; + logger.info( + `${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${ + data.stationInfo.chargingStationId + } (hashId: ${data.stationInfo.hashId}) stopped (${ + this.numberOfStartedChargingStations + } started from ${this.numberOfChargingStations})` + ); }; private workerEventUpdated = (data: ChargingStationData) => {