X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Findex.js;h=d8ea947172d9dcdf268475b40a19176cb2782fbc;hb=ead548f258fdd8fe23caefedb5f8eb25f11bb6c3;hp=3591d11c91546bed3e7c8fcdc845c3563e680bae;hpb=7dde0b73302613be132c41e1f28a42de555dc2b6;p=e-mobility-charging-stations-simulator.git diff --git a/src/index.js b/src/index.js index 3591d11c..d8ea9471 100644 --- a/src/index.js +++ b/src/index.js @@ -1,47 +1,33 @@ 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; - } + logger.debug('%s Configuration: %j', Utils.logPrefix(), Configuration.getConfig()); // 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