const Configuration = require('./utils/Configuration');
-const EventEmitter = require('events');
const Utils = require('./utils/Utils');
const Wrk = require('./charging-station/Worker');
-const fs = require('fs');
const logger = require('./utils/Logger');
class Bootstrap {
static async start() {
try {
logger.info('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig());
- if (Configuration.useWorkerPool && Configuration.getWorkerPoolSize() > 10) {
- EventEmitter.defaultMaxListeners = Configuration.getWorkerPoolSize() + 1;
- }
// Start each ChargingStation object in a worker thread
- if (Configuration.getChargingStationTemplateURLs()) {
- Configuration.getChargingStationTemplateURLs().forEach((stationURL) => {
+ if (Configuration.getStationTemplateURLs()) {
+ let numStationsTotal = 0;
+ Configuration.getStationTemplateURLs().forEach((stationURL) => {
try {
- // load file
- const fileDescriptor = fs.openSync(stationURL.file, 'r');
- const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
- fs.closeSync(fileDescriptor);
- const nbStation = (stationURL.numberOfStation ? stationURL.numberOfStation : 0);
+ const nbStation = stationURL.numberOfStation ? stationURL.numberOfStation : 0;
+ numStationsTotal += nbStation;
for (let index = 1; index <= nbStation; index++) {
const worker = new Wrk('./src/charging-station/StationWorker.js', {
index,
- template: JSON.parse(JSON.stringify(stationTemplate)),
- });
+ templateFile: stationURL.file,
+ }, numStationsTotal);
worker.start();
}
} catch (error) {
// eslint-disable-next-line no-console
- console.log('Template file' + stationURL.file + ' error' + error);
+ console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' '));
}
});
} else {
- const nbStation = Configuration.getNumberofChargingStation();
- for (let index = 1; index <= nbStation; index++) {
- const worker = new Wrk('./src/charging-station/StationWorker.js', {
- index,
- template: JSON.parse(JSON.stringify(Configuration.getChargingStationTemplate())),
- });
- worker.start();
- }
+ console.log('No stationTemplateURLs defined in configuration, exiting');
}
} catch (error) {
// eslint-disable-next-line no-console