Commit | Line | Data |
---|---|---|
6af9012e | 1 | import Configuration from './utils/Configuration'; |
46eb543c | 2 | import { StationWorkerData } from './types/Worker'; |
a4624c96 | 3 | import Utils from './utils/Utils'; |
6013bc53 | 4 | import WorkerFactory from './worker/WorkerFactory'; |
144cabe0 | 5 | import Wrk from './worker/Wrk'; |
7dde0b73 JB |
6 | |
7 | class Bootstrap { | |
a4624c96 | 8 | static async start() { |
7dde0b73 | 9 | try { |
6ecb15e4 | 10 | let numStationsTotal = 0; |
6013bc53 | 11 | const workerImplementation: Wrk = WorkerFactory.getWorkerImpl('./dist/charging-station/StationWorker.js'); |
a4624c96 | 12 | await workerImplementation.start(); |
6013bc53 | 13 | // Start ChargingStation object in worker thread |
2e6f5966 | 14 | if (Configuration.getStationTemplateURLs()) { |
4faad557 | 15 | for (const stationURL of Configuration.getStationTemplateURLs()) { |
7dde0b73 | 16 | try { |
e118beaa | 17 | const nbStations = stationURL.numberOfStations ? stationURL.numberOfStations : 0; |
e118beaa | 18 | for (let index = 1; index <= nbStations; index++) { |
46eb543c | 19 | const workerData: StationWorkerData = { |
7dde0b73 | 20 | index, |
3d2ff9e4 | 21 | templateFile: stationURL.file |
90225052 | 22 | }; |
a4624c96 | 23 | await workerImplementation.addElement(workerData); |
d392bb75 | 24 | numStationsTotal++; |
7dde0b73 JB |
25 | } |
26 | } catch (error) { | |
27 | // eslint-disable-next-line no-console | |
6013bc53 | 28 | console.error('Charging station start with template file ' + stationURL.file + ' error ', error); |
7dde0b73 | 29 | } |
3d2ff9e4 | 30 | } |
7dde0b73 | 31 | } else { |
d3a7883e | 32 | console.log('No stationTemplateURLs defined in configuration, exiting'); |
7dde0b73 | 33 | } |
6ecb15e4 JB |
34 | if (numStationsTotal === 0) { |
35 | console.log('No charging station template enabled in configuration, exiting'); | |
d4a73fb7 | 36 | } else { |
a4624c96 | 37 | console.log(`Charging station simulator started with ${numStationsTotal.toString()} charging station(s) and ${workerImplementation.size}${Utils.workerPoolInUse() ? `/${Configuration.getWorkerPoolMaxSize().toString()}` : ''} worker(s) concurrently running (${workerImplementation.maxElementsPerWorker} charging station(s) per worker)`); |
6ecb15e4 | 38 | } |
7dde0b73 JB |
39 | } catch (error) { |
40 | // eslint-disable-next-line no-console | |
6013bc53 | 41 | console.error('Bootstrap start error ', error); |
7dde0b73 JB |
42 | } |
43 | } | |
44 | } | |
45 | ||
a4624c96 JB |
46 | Bootstrap.start().catch( |
47 | (error) => { | |
48 | console.error(error); | |
49 | } | |
50 | ); |