X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=d12f78f9b326e79152a11e33d3ccf9f09f2bd2d6;hb=c0bbb3eaf0c5dc704ea92820a2666a68ffdc27ff;hp=0f2a26a831cd98ed2f9cfdeedd30e0faab82b4b8;hpb=9e9194c977f2100a92a4549e6562750499607706;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 0f2a26a8..d12f78f9 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -114,9 +114,17 @@ export class Bootstrap extends EventEmitter { ) } + public get numberOfProvisionedChargingStations (): number { + return [...this.templateStatistics.values()].reduce( + (accumulator, value) => accumulator + value.provisioned, + 0 + ) + } + public getState (): SimulatorState { return { version: this.version, + configuration: Configuration.getConfigurationData(), started: this.started, templateStatistics: this.templateStatistics } @@ -217,9 +225,13 @@ export class Bootstrap extends EventEmitter { ) console.info( chalk.green( - `Charging stations simulator ${ - this.version - } started with ${this.numberOfConfiguredChargingStations} configured charging station(s) from ${this.numberOfChargingStationTemplates} charging station template(s) and ${ + `Charging stations simulator ${this.version} started with ${ + this.numberOfConfiguredChargingStations + } configured and ${ + this.numberOfProvisionedChargingStations + } provisioned charging station(s) from ${ + this.numberOfChargingStationTemplates + } charging station template(s) and ${ Configuration.workerDynamicPoolInUse() ? `${workerConfiguration.poolMinSize}/` : '' }${this.workerImplementation?.size}${ Configuration.workerPoolInUse() ? `/${workerConfiguration.poolMaxSize}` : '' @@ -327,12 +339,18 @@ export class Bootstrap extends EventEmitter { let elementsPerWorker: number switch (workerConfiguration.elementsPerWorker) { case 'all': - elementsPerWorker = this.numberOfConfiguredChargingStations + elementsPerWorker = + this.numberOfConfiguredChargingStations + this.numberOfProvisionedChargingStations break case 'auto': elementsPerWorker = - this.numberOfConfiguredChargingStations > availableParallelism() - ? Math.round(this.numberOfConfiguredChargingStations / (availableParallelism() * 1.5)) + this.numberOfConfiguredChargingStations + this.numberOfProvisionedChargingStations > + availableParallelism() + ? Math.round( + (this.numberOfConfiguredChargingStations + + this.numberOfProvisionedChargingStations) / + (availableParallelism() * 1.5) + ) : 1 break default: @@ -359,7 +377,9 @@ export class Bootstrap extends EventEmitter { poolOptions: { messageHandler: this.messageHandler.bind(this) as MessageHandler, ...(workerConfiguration.resourceLimits != null && { - workerOptions: { resourceLimits: workerConfiguration.resourceLimits } + workerOptions: { + resourceLimits: workerConfiguration.resourceLimits + } }) } } @@ -370,12 +390,17 @@ export class Bootstrap extends EventEmitter { msg: ChargingStationWorkerMessage ): void { // logger.debug( - // `${this.logPrefix()} ${moduleName}.messageHandler: Worker channel message received: ${JSON.stringify( + // `${this.logPrefix()} ${moduleName}.messageHandler: Charging station worker message received: ${JSON.stringify( // msg, // undefined, // 2 // )}` // ) + // Skip worker message events processing + // eslint-disable-next-line @typescript-eslint/dot-notation + if (msg['uuid'] != null) { + return + } const { event, data } = msg try { switch (event) { @@ -399,12 +424,16 @@ export class Bootstrap extends EventEmitter { break default: throw new BaseError( - `Unknown charging station worker event: '${event}' received with data: ${JSON.stringify(data, undefined, 2)}` + `Unknown charging station worker message event: '${event}' received with data: ${JSON.stringify( + data, + undefined, + 2 + )}` ) } } catch (error) { logger.error( - `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${event}' event:`, + `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling charging station worker message event '${event}':`, error ) } @@ -417,7 +446,9 @@ export class Bootstrap extends EventEmitter { data.stationInfo.chargingStationId } (hashId: ${data.stationInfo.hashId}) added (${ this.numberOfAddedChargingStations - } added from ${this.numberOfConfiguredChargingStations} configured charging station(s))` + } added from ${this.numberOfConfiguredChargingStations} configured and ${ + this.numberOfProvisionedChargingStations + } provisioned charging station(s))` ) } @@ -432,7 +463,9 @@ export class Bootstrap extends EventEmitter { data.stationInfo.chargingStationId } (hashId: ${data.stationInfo.hashId}) deleted (${ this.numberOfAddedChargingStations - } added from ${this.numberOfConfiguredChargingStations} configured charging station(s))` + } added from ${this.numberOfConfiguredChargingStations} configured and ${ + this.numberOfProvisionedChargingStations + } provisioned charging station(s))` ) } @@ -489,6 +522,7 @@ export class Bootstrap extends EventEmitter { const templateName = buildTemplateName(stationTemplateUrl.file) this.templateStatistics.set(templateName, { configured: stationTemplateUrl.numberOfStations, + provisioned: stationTemplateUrl.provisionedNumberOfStations ?? 0, added: 0, started: 0, indexes: new Set()