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