Make the station worker self contained.
[e-mobility-charging-stations-simulator.git] / src / index.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 {
9 logger.info('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig());
7dde0b73 10 // Start each ChargingStation object in a worker thread
2e6f5966 11 if (Configuration.getStationTemplateURLs()) {
6798437b 12 let numStationsTotal = 0;
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 {
2e6f5966 30 console.log('No stationURLS defined in configuration, exiting');
7dde0b73
JB
31 }
32 } catch (error) {
33 // eslint-disable-next-line no-console
34 console.log('Bootstrap start error ' + JSON.stringify(error, null, ' '));
35 }
36 }
37}
38
39Bootstrap.start();