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