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';
10 let numStationsTotal
= 0;
11 const workerImplementation
: Wrk
= WorkerFactory
.getWorkerImpl
<StationWorkerData
>('./dist/charging-station/StationWorker.js', Configuration
.getWorkerProcess(), {
12 poolMaxSize
: Configuration
.getWorkerPoolMaxSize(),
13 poolMinSize
: Configuration
.getWorkerPoolMinSize(),
14 elementsPerWorker
: Configuration
.getChargingStationsPerWorker()
16 await workerImplementation
.start();
17 // Start ChargingStation object in worker thread
18 if (Configuration
.getStationTemplateURLs()) {
19 for (const stationURL
of Configuration
.getStationTemplateURLs()) {
21 const nbStations
= stationURL
.numberOfStations
? stationURL
.numberOfStations
: 0;
22 for (let index
= 1; index
<= nbStations
; index
++) {
23 const workerData
: StationWorkerData
= {
25 templateFile
: stationURL
.file
27 await workerImplementation
.addElement(workerData
);
31 // eslint-disable-next-line no-console
32 console
.error('Charging station start with template file ' + stationURL
.file
+ ' error ', error
);
36 console
.log('No stationTemplateURLs defined in configuration, exiting');
38 if (numStationsTotal
=== 0) {
39 console
.log('No charging station template enabled in configuration, exiting');
41 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)`);
44 // eslint-disable-next-line no-console
45 console
.error('Bootstrap start error ', error
);
50 Bootstrap
.start().catch(