| 1 | import Configuration from './utils/Configuration.js'; |
| 2 | import Utils from './utils/Utils.js'; |
| 3 | import Wrk from './charging-station/Worker.js'; |
| 4 | import logger from './utils/Logger.js'; |
| 5 | |
| 6 | class Bootstrap { |
| 7 | static async start() { |
| 8 | try { |
| 9 | logger.debug('%s Configuration: %j', Utils.logPrefix(), Configuration.getConfig()); |
| 10 | let numStationsTotal = 0; |
| 11 | // Start each ChargingStation object in a worker thread |
| 12 | if (Configuration.getStationTemplateURLs()) { |
| 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 | if (numStationsTotal === 0) { |
| 33 | console.log('No charging station template enabled in configuration, exiting'); |
| 34 | } else { |
| 35 | console.log('Charging station simulator started with ' + numStationsTotal + ' charging station(s)'); |
| 36 | } |
| 37 | } catch (error) { |
| 38 | // eslint-disable-next-line no-console |
| 39 | console.log('Bootstrap start error ' + JSON.stringify(error, null, ' ')); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | Bootstrap.start(); |