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