Rename index.js to start.js
[e-mobility-charging-stations-simulator.git] / src / start.js
CommitLineData
7dde0b73 1const Configuration = require('./utils/Configuration');
7dde0b73
JB
2const Utils = require('./utils/Utils');
3const Wrk = require('./charging-station/Worker');
7dde0b73
JB
4const logger = require('./utils/Logger');
5
6class Bootstrap {
7 static async start() {
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
JB
17 for (let index = 1; index <= nbStation; index++) {
18 const worker = new Wrk('./src/charging-station/StationWorker.js', {
19 index,
2e6f5966 20 templateFile: stationURL.file,
6798437b 21 }, numStationsTotal);
7dde0b73
JB
22 worker.start();
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 {
d752344e 35 console.log('Charging station simulator started with ' + numStationsTotal + ' 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();