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 for (let index
= 1; index
<= nbStations
; index
++) {
23 templateFile
: stationURL
.file
25 if (Configuration
.useWorkerPool()) {
26 worker
= new Wrk('./dist/charging-station/StationWorker.js', workerData
);
27 worker
.start().catch(() => { });
28 numConcurrentWorkers
= worker
.getWorkerPoolSize();
29 numStationsTotal
= numConcurrentWorkers
;
30 // Start Wrk sequentially to optimize memory at start time
31 await Utils
.sleep(Constants
.START_WORKER_DELAY
);
32 } else if (!Configuration
.useWorkerPool() && (chargingStationsPerWorkerCounter
=== 0 || chargingStationsPerWorkerCounter
>= chargingStationsPerWorker
)) {
33 // Start new Wrk with one charging station
34 worker
= new Wrk('./dist/charging-station/StationWorker.js', workerData
, chargingStationsPerWorker
);
35 worker
.start().catch(() => { });
36 numConcurrentWorkers
++;
37 chargingStationsPerWorkerCounter
= 1;
39 // Start Wrk sequentially to optimize memory at start time
40 await Utils
.sleep(Constants
.START_WORKER_DELAY
);
41 } else if (!Configuration
.useWorkerPool()) {
42 // Add charging station to existing Wrk
43 worker
.addWorkerElement(workerData
);
44 chargingStationsPerWorkerCounter
++;
49 // eslint-disable-next-line no-console
50 console
.log('Charging station start with template file ' + stationURL
.file
+ ' error ' + JSON
.stringify(error
, null, ' '));
54 console
.log('No stationTemplateURLs defined in configuration, exiting');
56 if (numStationsTotal
=== 0) {
57 console
.log('No charging station template enabled in configuration, exiting');
58 } else if (Configuration
.useWorkerPool()) {
59 console
.log('Charging station simulator started with ' + numStationsTotal
.toString() + ' charging station(s) and ' + numConcurrentWorkers
.toString() + '/' + Configuration
.getWorkerPoolMaxSize().toString() + ' worker(s) concurrently running');
61 console
.log('Charging station simulator started with ' + numStationsTotal
.toString() + ' charging station(s) and ' + numConcurrentWorkers
.toString() + ' worker(s) concurrently running');
64 // eslint-disable-next-line no-console
65 console
.log('Bootstrap start error ' + JSON
.stringify(error
, null, ' '));
70 Bootstrap
.start().catch(