Fix rounding helper
[e-mobility-charging-stations-simulator.git] / src / start.ts
1 import Configuration from './utils/Configuration';
2 import { StationTemplateURL } from './types/ConfigurationData';
3 import Wrk from './charging-station/Worker';
4
5 class Bootstrap {
6 static start() {
7 try {
8 let numStationsTotal = 0;
9 let numConcurrentWorkers = 0;
10 // Start each ChargingStation object in a worker thread
11 if (Configuration.getStationTemplateURLs()) {
12 Configuration.getStationTemplateURLs().forEach((stationURL: StationTemplateURL) => {
13 try {
14 const nbStations = stationURL.numberOfStations ? stationURL.numberOfStations : 0;
15 numStationsTotal += nbStations;
16 for (let index = 1; index <= nbStations; index++) {
17 const worker = new Wrk('./dist/charging-station/StationWorker.js', {
18 index,
19 templateFile: stationURL.file,
20 }, numStationsTotal);
21 worker.start().catch(() => {});
22 numConcurrentWorkers = worker.concurrentWorkers;
23 }
24 } catch (error) {
25 // eslint-disable-next-line no-console
26 console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' '));
27 }
28 });
29 } else {
30 console.log('No stationTemplateURLs defined in configuration, exiting');
31 }
32 if (numStationsTotal === 0) {
33 console.log('No charging station template enabled in configuration, exiting');
34 } else {
35 console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) of ' + numConcurrentWorkers.toString() + ' concurrently running');
36 }
37 } catch (error) {
38 // eslint-disable-next-line no-console
39 console.log('Bootstrap start error ' + JSON.stringify(error, null, ' '));
40 }
41 }
42 }
43
44 Bootstrap.start();