Commit | Line | Data |
---|---|---|
7dde0b73 | 1 | const Configuration = require('./utils/Configuration'); |
7dde0b73 JB |
2 | const Utils = require('./utils/Utils'); |
3 | const Wrk = require('./charging-station/Worker'); | |
4 | const fs = require('fs'); | |
5 | const logger = require('./utils/Logger'); | |
6 | ||
7 | class 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()) { | |
6798437b | 13 | let numStationsTotal = 0; |
7dde0b73 JB |
14 | Configuration.getChargingStationTemplateURLs().forEach((stationURL) => { |
15 | try { | |
dcab13bd | 16 | // Load file |
7dde0b73 JB |
17 | const fileDescriptor = fs.openSync(stationURL.file, 'r'); |
18 | const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8')); | |
19 | fs.closeSync(fileDescriptor); | |
20 | const nbStation = (stationURL.numberOfStation ? stationURL.numberOfStation : 0); | |
6798437b | 21 | numStationsTotal += nbStation; |
7dde0b73 JB |
22 | for (let index = 1; index <= nbStation; index++) { |
23 | const worker = new Wrk('./src/charging-station/StationWorker.js', { | |
24 | index, | |
25 | template: JSON.parse(JSON.stringify(stationTemplate)), | |
6798437b | 26 | }, numStationsTotal); |
7dde0b73 JB |
27 | worker.start(); |
28 | } | |
29 | } catch (error) { | |
30 | // eslint-disable-next-line no-console | |
31 | console.log('Template file' + stationURL.file + ' error' + error); | |
32 | } | |
33 | }); | |
34 | } else { | |
35 | const nbStation = Configuration.getNumberofChargingStation(); | |
36 | for (let index = 1; index <= nbStation; index++) { | |
37 | const worker = new Wrk('./src/charging-station/StationWorker.js', { | |
38 | index, | |
39 | template: JSON.parse(JSON.stringify(Configuration.getChargingStationTemplate())), | |
6798437b | 40 | }, nbStation); |
7dde0b73 JB |
41 | worker.start(); |
42 | } | |
43 | } | |
44 | } catch (error) { | |
45 | // eslint-disable-next-line no-console | |
46 | console.log('Bootstrap start error ' + JSON.stringify(error, null, ' ')); | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | Bootstrap.start(); |