Finalize Constants conversion to ES6 module definition.
[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');
4const fs = require('fs');
5const logger = require('./utils/Logger');
6
7class Bootstrap {
8 static async start() {
9 try {
10 logger.info('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig());
7dde0b73
JB
11 // Start each ChargingStation object in a worker thread
12 if (Configuration.getChargingStationTemplateURLs()) {
13 Configuration.getChargingStationTemplateURLs().forEach((stationURL) => {
14 try {
15 // load file
16 const fileDescriptor = fs.openSync(stationURL.file, 'r');
17 const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
18 fs.closeSync(fileDescriptor);
19 const nbStation = (stationURL.numberOfStation ? stationURL.numberOfStation : 0);
20 for (let index = 1; index <= nbStation; index++) {
21 const worker = new Wrk('./src/charging-station/StationWorker.js', {
22 index,
23 template: JSON.parse(JSON.stringify(stationTemplate)),
24 });
25 worker.start();
26 }
27 } catch (error) {
28 // eslint-disable-next-line no-console
29 console.log('Template file' + stationURL.file + ' error' + error);
30 }
31 });
32 } else {
33 const nbStation = Configuration.getNumberofChargingStation();
34 for (let index = 1; index <= nbStation; index++) {
35 const worker = new Wrk('./src/charging-station/StationWorker.js', {
36 index,
37 template: JSON.parse(JSON.stringify(Configuration.getChargingStationTemplate())),
38 });
39 worker.start();
40 }
41 }
42 } catch (error) {
43 // eslint-disable-next-line no-console
44 console.log('Bootstrap start error ' + JSON.stringify(error, null, ' '));
45 }
46 }
47}
48
49Bootstrap.start();