Initial portage to TypeScript.
[e-mobility-charging-stations-simulator.git] / src / start.ts
CommitLineData
6af9012e
JB
1import Configuration from './utils/Configuration';
2import Utils from './utils/Utils';
3import Wrk from './charging-station/Worker';
4import logger from './utils/Logger';
7dde0b73
JB
5
6class Bootstrap {
6af9012e 7 static start() {
7dde0b73 8 try {
ead548f2 9 logger.debug('%s Configuration: %j', Utils.logPrefix(), Configuration.getConfig());
6ecb15e4 10 let numStationsTotal = 0;
7dde0b73 11 // Start each ChargingStation object in a worker thread
2e6f5966 12 if (Configuration.getStationTemplateURLs()) {
2e6f5966 13 Configuration.getStationTemplateURLs().forEach((stationURL) => {
7dde0b73 14 try {
2e6f5966 15 const nbStation = stationURL.numberOfStation ? stationURL.numberOfStation : 0;
6798437b 16 numStationsTotal += nbStation;
7dde0b73 17 for (let index = 1; index <= nbStation; index++) {
6af9012e 18 const worker = new Wrk('./dist/charging-station/StationWorker.js', {
7dde0b73 19 index,
2e6f5966 20 templateFile: stationURL.file,
6798437b 21 }, numStationsTotal);
6af9012e 22 worker.start().catch(() => {});
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 {
6af9012e 35 console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s)');
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();