Warn about deprecated configuration key at startup.
[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 // Start each ChargingStation object in a worker thread
10 if (Configuration.getStationTemplateURLs()) {
11 Configuration.getStationTemplateURLs().forEach((stationURL: StationTemplateURL) => {
12 try {
13 const nbStations = stationURL.numberOfStations ? stationURL.numberOfStations : 0;
14 numStationsTotal += nbStations;
15 for (let index = 1; index <= nbStations; index++) {
16 const worker = new Wrk('./dist/charging-station/StationWorker.js', {
17 index,
18 templateFile: stationURL.file,
19 }, numStationsTotal);
20 worker.start().catch(() => {});
21 }
22 } catch (error) {
23 // eslint-disable-next-line no-console
24 console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' '));
25 }
26 });
27 } else {
28 console.log('No stationTemplateURLs defined in configuration, exiting');
29 }
30 if (numStationsTotal === 0) {
31 console.log('No charging station template enabled in configuration, exiting');
32 } else {
33 console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s)');
34 }
35 } catch (error) {
36 // eslint-disable-next-line no-console
37 console.log('Bootstrap start error ' + JSON.stringify(error, null, ' '));
38 }
39 }
40 }
41
42 Bootstrap.start();