refactor(simulator): move configuration checks at initialization
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 2 Feb 2023 19:45:00 +0000 (20:45 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 2 Feb 2023 19:45:00 +0000 (20:45 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts

index 66a424193270ebc033f36dc49eda67fb8fc66c72..113a9f1dae77e389a79a88b8367a5349088f8f7c 100644 (file)
@@ -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();
   }