| 1 | const Configuration = require('./utils/Configuration'); |
| 2 | const Utils = require('./utils/Utils'); |
| 3 | const Wrk = require('./charging-station/Worker'); |
| 4 | const logger = require('./utils/Logger'); |
| 5 | |
| 6 | class Bootstrap { |
| 7 | static async start() { |
| 8 | try { |
| 9 | logger.info('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig()); |
| 10 | // Start each ChargingStation object in a worker thread |
| 11 | if (Configuration.getStationTemplateURLs()) { |
| 12 | let numStationsTotal = 0; |
| 13 | Configuration.getStationTemplateURLs().forEach((stationURL) => { |
| 14 | try { |
| 15 | const nbStation = stationURL.numberOfStation ? stationURL.numberOfStation : 0; |
| 16 | numStationsTotal += nbStation; |
| 17 | for (let index = 1; index <= nbStation; index++) { |
| 18 | const worker = new Wrk('./src/charging-station/StationWorker.js', { |
| 19 | index, |
| 20 | templateFile: stationURL.file, |
| 21 | }, numStationsTotal); |
| 22 | worker.start(); |
| 23 | } |
| 24 | } catch (error) { |
| 25 | // eslint-disable-next-line no-console |
| 26 | console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' ')); |
| 27 | } |
| 28 | }); |
| 29 | } else { |
| 30 | console.log('No stationTemplateURLs defined in configuration, exiting'); |
| 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 | |
| 39 | Bootstrap.start(); |