X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fstart.ts;h=8c56e635d36d1d415853f27968766f3fa5af709f;hb=b5977da89e7a5d292b060c7af75802ee207eb2cc;hp=67df5a3f44b1538ebabc3eeb4f79d5c87afaf6a7;hpb=5fdab605ce885d9a9fb21ac47c6d0766bd3673bb;p=e-mobility-charging-stations-simulator.git diff --git a/src/start.ts b/src/start.ts index 67df5a3f..8c56e635 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,60 +1,11 @@ -import Configuration from './utils/Configuration'; -import Constants from './utils/Constants'; -import Utils from './utils/Utils'; -import WorkerData from './types/WorkerData'; -import Wrk from './charging-station/Worker'; +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -class Bootstrap { - static async start() { - try { - let numStationsTotal = 0; - let numConcurrentWorkers = 0; - let worker: Wrk; - const chargingStationsPerWorker = Configuration.getChargingStationsPerWorker(); - let counter = 0; - // Start each ChargingStation object in a worker thread - if (Configuration.getStationTemplateURLs()) { - for await (const stationURL of Configuration.getStationTemplateURLs()) { - try { - const nbStations = stationURL.numberOfStations ? stationURL.numberOfStations : 0; - numStationsTotal += nbStations; - for (let index = 1; index <= nbStations; index++) { - const workerData = { - index, - templateFile: stationURL.file - } as WorkerData; - if (counter === 0 || counter === chargingStationsPerWorker) { - // Start new worker with one charging station - worker = new Wrk('./dist/charging-station/StationWorker.js', workerData, numStationsTotal); - worker.start().catch(() => { }); - counter = 0; - // Start workers sequentially to optimize memory at start time - await Utils.sleep(Constants.START_WORKER_DELAY); - } else { - // Add charging station to existing Worker - worker.addChargingStation(workerData, numStationsTotal); - } - counter++; - numConcurrentWorkers = worker.concurrentWorkers; - } - } catch (error) { - // eslint-disable-next-line no-console - console.log('Charging station start with template file ' + stationURL.file + ' error ' + JSON.stringify(error, null, ' ')); - } - } - } else { - console.log('No stationTemplateURLs defined in configuration, exiting'); - } - if (numStationsTotal === 0) { - console.log('No charging station template enabled in configuration, exiting'); - } else { - console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) of ' + numConcurrentWorkers.toString() + ' concurrently running'); - } - } catch (error) { - // eslint-disable-next-line no-console - console.log('Bootstrap start error ' + JSON.stringify(error, null, ' ')); - } - } -} +import chalk from 'chalk' + +import { Bootstrap } from './charging-station/index.js' -Bootstrap.start(); +try { + await Bootstrap.getInstance().start() +} catch (error) { + console.error(chalk.red('Startup error: '), error) +}