1 import Configuration from
'./utils/Configuration';
2 import Constants from
'./utils/Constants';
3 import Utils from
'./utils/Utils';
4 import WorkerData from
'./types/WorkerData';
5 import Wrk from
'./charging-station/Worker';
10 let numStationsTotal
= 0;
11 let numConcurrentWorkers
= 0;
12 const chargingStationsPerWorker
= Configuration
.getChargingStationsPerWorker();
13 let chargingStationsPerWorkerCounter
= 0;
15 // Start each ChargingStation object in a worker thread
16 if (Configuration
.getStationTemplateURLs()) {
17 for (const stationURL
of Configuration
.getStationTemplateURLs()) {
19 const nbStations
= stationURL
.numberOfStations
? stationURL
.numberOfStations
: 0;
20 numStationsTotal
+= nbStations
;
21 for (let index
= 1; index
<= nbStations
; index
++) {
24 templateFile
: stationURL
.file
26 if (Configuration
.useWorkerPool()) {
27 worker
= new Wrk('./dist/charging-station/StationWorker.js', workerData
);
28 worker
.start().catch(() => { });
29 numConcurrentWorkers
= Configuration
.getWorkerPoolSize();
30 } else if (!Configuration
.useWorkerPool() && (chargingStationsPerWorkerCounter
=== 0 || chargingStationsPerWorkerCounter
=== chargingStationsPerWorker
)) {
31 // Start new Wrk with one charging station
32 worker
= new Wrk('./dist/charging-station/StationWorker.js', workerData
);
33 worker
.start().catch(() => { });
34 numConcurrentWorkers
++;
35 chargingStationsPerWorkerCounter
= 1;
36 // Start Wrk sequentially to optimize memory at start time
37 await Utils
.sleep(Constants
.START_WORKER_DELAY
);
38 } else if (!Configuration
.useWorkerPool()) {
39 // Add charging station to existing Wrk
40 worker
.addWorkerElement(workerData
);
41 chargingStationsPerWorkerCounter
++;
45 // eslint-disable-next-line no-console
46 console
.log('Charging station start with template file ' + stationURL
.file
+ ' error ' + JSON
.stringify(error
, null, ' '));
50 console
.log('No stationTemplateURLs defined in configuration, exiting');
52 if (numStationsTotal
=== 0) {
53 console
.log('No charging station template enabled in configuration, exiting');
55 console
.log('Charging station simulator started with ' + numStationsTotal
.toString() + ' charging station(s) of ' + numConcurrentWorkers
.toString() + ' concurrently running');
58 // eslint-disable-next-line no-console
59 console
.log('Bootstrap start error ' + JSON
.stringify(error
, null, ' '));
64 Bootstrap
.start().catch(