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