X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=34ac90f3f3e4ba2e211d47ef3639907e5ccff066;hb=2bb3c92f49572f8d81f40620df42de19217a6b4c;hp=64953a9687a8f730a233ce7517ffa1f2842bbd3c;hpb=195c627f62717d86ebc1c3dfd4a69f25277ceb70;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 64953a96..34ac90f3 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -64,7 +64,6 @@ export class Bootstrap extends EventEmitter { private storage?: Storage private readonly templateStatistics: Map private readonly version: string = version - private initializedCounters: boolean private started: boolean private starting: boolean private stopping: boolean @@ -81,16 +80,15 @@ export class Bootstrap extends EventEmitter { this.started = false this.starting = false this.stopping = false - this.initializedCounters = false this.uiServerStarted = false this.templateStatistics = new Map() - this.initializeWorkerImplementation( - Configuration.getConfigurationSection(ConfigurationSection.worker) - ) this.uiServer = UIServerFactory.getUIServerImplementation( Configuration.getConfigurationSection(ConfigurationSection.uiServer) ) this.initializeCounters() + this.initializeWorkerImplementation( + Configuration.getConfigurationSection(ConfigurationSection.worker) + ) Configuration.configurationChangeCallback = async () => { if (isMainThread) { await Bootstrap.getInstance().restart() @@ -177,7 +175,6 @@ export class Bootstrap extends EventEmitter { ) } ) - this.initializeCounters() // eslint-disable-next-line @typescript-eslint/unbound-method if (isAsyncFunction(this.workerImplementation?.start)) { await this.workerImplementation.start() @@ -278,7 +275,6 @@ export class Bootstrap extends EventEmitter { await this.workerImplementation?.stop() this.removeAllListeners() this.uiServer.clearCaches() - this.initializedCounters = false await this.storage?.close() delete this.storage this.started = false @@ -293,10 +289,6 @@ export class Bootstrap extends EventEmitter { private async restart (): Promise { await this.stop() - // FIXME: initialize worker implementation only if the worker section has changed - this.initializeWorkerImplementation( - Configuration.getConfigurationSection(ConfigurationSection.worker) - ) if ( this.uiServerStarted && Configuration.getConfigurationSection(ConfigurationSection.uiServer) @@ -305,6 +297,11 @@ export class Bootstrap extends EventEmitter { this.uiServer.stop() this.uiServerStarted = false } + this.initializeCounters() + // FIXME: initialize worker implementation only if the worker section has changed + this.initializeWorkerImplementation( + Configuration.getConfigurationSection(ConfigurationSection.worker) + ) await this.start() } @@ -499,47 +496,44 @@ export class Bootstrap extends EventEmitter { } private initializeCounters (): void { - if (!this.initializedCounters) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const stationTemplateUrls = Configuration.getStationTemplateUrls()! - if (isNotEmptyArray(stationTemplateUrls)) { - for (const stationTemplateUrl of stationTemplateUrls) { - const templateName = buildTemplateName(stationTemplateUrl.file) - this.templateStatistics.set(templateName, { - configured: stationTemplateUrl.numberOfStations, - added: 0, - started: 0, - indexes: new Set() - }) - this.uiServer.chargingStationTemplates.add(templateName) - } - if (this.templateStatistics.size !== stationTemplateUrls.length) { - console.error( - chalk.red( - "'stationTemplateUrls' contains duplicate entries, please check your configuration" - ) - ) - exit(exitCodes.duplicateChargingStationTemplateUrls) - } - } else { - console.error( - chalk.red("'stationTemplateUrls' not defined or empty, please check your configuration") - ) - exit(exitCodes.missingChargingStationsConfiguration) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const stationTemplateUrls = Configuration.getStationTemplateUrls()! + if (isNotEmptyArray(stationTemplateUrls)) { + for (const stationTemplateUrl of stationTemplateUrls) { + const templateName = buildTemplateName(stationTemplateUrl.file) + this.templateStatistics.set(templateName, { + configured: stationTemplateUrl.numberOfStations, + added: 0, + started: 0, + indexes: new Set() + }) + this.uiServer.chargingStationTemplates.add(templateName) } - if ( - this.numberOfConfiguredChargingStations === 0 && - Configuration.getConfigurationSection(ConfigurationSection.uiServer) - .enabled !== true - ) { + if (this.templateStatistics.size !== stationTemplateUrls.length) { console.error( chalk.red( - "'stationTemplateUrls' has no charging station enabled and UI server is disabled, please check your configuration" + "'stationTemplateUrls' contains duplicate entries, please check your configuration" ) ) - exit(exitCodes.noChargingStationTemplates) + exit(exitCodes.duplicateChargingStationTemplateUrls) } - this.initializedCounters = true + } else { + console.error( + chalk.red("'stationTemplateUrls' not defined or empty, please check your configuration") + ) + exit(exitCodes.missingChargingStationsConfiguration) + } + if ( + this.numberOfConfiguredChargingStations === 0 && + Configuration.getConfigurationSection(ConfigurationSection.uiServer) + .enabled !== true + ) { + console.error( + chalk.red( + "'stationTemplateUrls' has no charging station enabled and UI server is disabled, please check your configuration" + ) + ) + exit(exitCodes.noChargingStationTemplates) } }