From: Jérôme Benoit Date: Thu, 2 Feb 2023 19:45:00 +0000 (+0100) Subject: refactor(simulator): move configuration checks at initialization X-Git-Tag: v1.1.93~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=846d285145c208d251fedf80426c7a4abf12d731;p=e-mobility-charging-stations-simulator.git refactor(simulator): move configuration checks at initialization Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 66a42419..113a9f1d 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -102,32 +102,25 @@ export class Bootstrap { ); } } - if (this.numberOfChargingStations === 0) { - console.warn( - chalk.yellow('No charging station template enabled in configuration, exiting') - ); - process.exit(exitCodes.noChargingStationTemplates); - } else { - console.info( - chalk.green( - `Charging stations simulator ${ - this.version - } started with ${this.numberOfChargingStations.toString()} charging station(s) from ${this.numberOfChargingStationTemplates.toString()} configured charging station template(s) and ${ - ChargingStationUtils.workerDynamicPoolInUse() - ? `${Configuration.getWorker().poolMinSize?.toString()}/` - : '' - }${this.workerImplementation?.size}${ - ChargingStationUtils.workerPoolInUse() - ? `/${Configuration.getWorker().poolMaxSize?.toString()}` - : '' - } worker(s) concurrently running in '${Configuration.getWorker().processType}' mode${ - !Utils.isNullOrUndefined(this.workerImplementation?.maxElementsPerWorker) - ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)` - : '' - }` - ) - ); - } + console.info( + chalk.green( + `Charging stations simulator ${ + this.version + } started with ${this.numberOfChargingStations.toString()} charging station(s) from ${this.numberOfChargingStationTemplates.toString()} configured charging station template(s) and ${ + ChargingStationUtils.workerDynamicPoolInUse() + ? `${Configuration.getWorker().poolMinSize?.toString()}/` + : '' + }${this.workerImplementation?.size}${ + ChargingStationUtils.workerPoolInUse() + ? `/${Configuration.getWorker().poolMaxSize?.toString()}` + : '' + } worker(s) concurrently running in '${Configuration.getWorker().processType}' mode${ + !Utils.isNullOrUndefined(this.workerImplementation?.maxElementsPerWorker) + ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)` + : '' + }` + ) + ); this.started = true; } catch (error) { console.error(chalk.red('Bootstrap start error: '), error); @@ -260,6 +253,10 @@ export class Bootstrap { ); process.exit(exitCodes.missingChargingStationsConfiguration); } + if (this.numberOfChargingStations === 0) { + console.warn(chalk.yellow('No charging station template enabled in configuration, exiting')); + process.exit(exitCodes.noChargingStationTemplates); + } this.numberOfStartedChargingStations = 0; this.initializeWorkerImplementation(); }