Commit | Line | Data |
---|---|---|
6af9012e | 1 | import Configuration from './utils/Configuration'; |
e118beaa | 2 | import { StationTemplateURL } from './types/ConfigurationData'; |
6af9012e JB |
3 | import Utils from './utils/Utils'; |
4 | import Wrk from './charging-station/Worker'; | |
5 | import logger from './utils/Logger'; | |
7dde0b73 JB |
6 | |
7 | class Bootstrap { | |
6af9012e | 8 | static start() { |
7dde0b73 | 9 | try { |
ead548f2 | 10 | logger.debug('%s Configuration: %j', Utils.logPrefix(), Configuration.getConfig()); |
6ecb15e4 | 11 | let numStationsTotal = 0; |
7dde0b73 | 12 | // Start each ChargingStation object in a worker thread |
2e6f5966 | 13 | if (Configuration.getStationTemplateURLs()) { |
e118beaa | 14 | Configuration.getStationTemplateURLs().forEach((stationURL: StationTemplateURL) => { |
7dde0b73 | 15 | try { |
e118beaa JB |
16 | const nbStations = stationURL.numberOfStations ? stationURL.numberOfStations : 0; |
17 | numStationsTotal += nbStations; | |
18 | for (let index = 1; index <= nbStations; index++) { | |
6af9012e | 19 | const worker = new Wrk('./dist/charging-station/StationWorker.js', { |
7dde0b73 | 20 | index, |
2e6f5966 | 21 | templateFile: stationURL.file, |
6798437b | 22 | }, numStationsTotal); |
6af9012e | 23 | worker.start().catch(() => {}); |
7dde0b73 JB |
24 | } |
25 | } catch (error) { | |
26 | // eslint-disable-next-line no-console | |
2e6f5966 | 27 | console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' ')); |
7dde0b73 JB |
28 | } |
29 | }); | |
30 | } else { | |
d3a7883e | 31 | console.log('No stationTemplateURLs defined in configuration, exiting'); |
7dde0b73 | 32 | } |
6ecb15e4 JB |
33 | if (numStationsTotal === 0) { |
34 | console.log('No charging station template enabled in configuration, exiting'); | |
d4a73fb7 | 35 | } else { |
6af9012e | 36 | console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s)'); |
6ecb15e4 | 37 | } |
7dde0b73 JB |
38 | } catch (error) { |
39 | // eslint-disable-next-line no-console | |
40 | console.log('Bootstrap start error ' + JSON.stringify(error, null, ' ')); | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | Bootstrap.start(); |