X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Findex.js;h=62e705b2b6bd599e21b7211b5200f770864bf15d;hb=9b25a525133f0b7d8e57a566dc1e841c97318d16;hp=3f47f1fe0b1806b8088014a59c46a05a01edcd1a;hpb=dcab13bd38c8362aa507d29bc0eb5ce36b27a753;p=e-mobility-charging-stations-simulator.git diff --git a/src/index.js b/src/index.js index 3f47f1fe..62e705b2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,45 +1,33 @@ const Configuration = require('./utils/Configuration'); 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()); + logger.debug('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig()); // Start each ChargingStation object in a worker thread - if (Configuration.getChargingStationTemplateURLs()) { + if (Configuration.getStationTemplateURLs()) { let numStationsTotal = 0; - Configuration.getChargingStationTemplateURLs().forEach((stationURL) => { + 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())), - }, nbStation); - worker.start(); - } + console.log('No stationTemplateURLs defined in configuration, exiting'); } } catch (error) { // eslint-disable-next-line no-console