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