X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=6eacfff46c462655a10a84d5209f545424694701;hb=24dc52e9f4bd2ff4539955f169333ee3902bc95e;hp=ad8c9b0c16bd5d37720be453468d6686717a1876;hpb=ea32ea059bfdd7134abe2ba349985e5b15bc1d06;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index ad8c9b0c..6eacfff4 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -81,12 +81,15 @@ export class Bootstrap extends EventEmitter { this.started = false this.starting = false this.stopping = false + this.initializedCounters = false this.uiServerStarted = false + this.templateStatistics = new Map() + this.initializeWorkerImplementation( + Configuration.getConfigurationSection(ConfigurationSection.worker) + ) this.uiServer = UIServerFactory.getUIServerImplementation( Configuration.getConfigurationSection(ConfigurationSection.uiServer) ) - this.templateStatistics = new Map() - this.initializedCounters = false this.initializeCounters() Configuration.configurationChangeCallback = async () => { if (isMainThread) { @@ -175,11 +178,12 @@ export class Bootstrap extends EventEmitter { } ) this.initializeCounters() - const workerConfiguration = Configuration.getConfigurationSection( - ConfigurationSection.worker - ) - this.initializeWorkerImplementation(workerConfiguration) - await this.workerImplementation?.start() + // eslint-disable-next-line @typescript-eslint/unbound-method + if (isAsyncFunction(this.workerImplementation?.start)) { + await this.workerImplementation.start() + } else { + (this.workerImplementation?.start as () => void)() + } const performanceStorageConfiguration = Configuration.getConfigurationSection( ConfigurationSection.performanceStorage @@ -220,6 +224,9 @@ export class Bootstrap extends EventEmitter { ) } } + const workerConfiguration = Configuration.getConfigurationSection( + ConfigurationSection.worker + ) console.info( chalk.green( `Charging stations simulator ${ @@ -269,7 +276,6 @@ export class Bootstrap extends EventEmitter { console.error(chalk.red('Error while waiting for charging stations to stop: '), error) } await this.workerImplementation?.stop() - delete this.workerImplementation this.removeAllListeners() this.uiServer.clearCaches() this.initializedCounters = false @@ -287,6 +293,10 @@ export class Bootstrap extends EventEmitter { private async restart (): Promise { await this.stop() + // FIXME: initialize worker implementation only if the worker section has changed + this.initializeWorkerImplementation( + Configuration.getConfigurationSection(ConfigurationSection.worker) + ) if ( this.uiServerStarted && Configuration.getConfigurationSection(ConfigurationSection.uiServer) @@ -348,7 +358,7 @@ export class Bootstrap extends EventEmitter { workerConfiguration.processType!, { workerStartDelay: workerConfiguration.startDelay, - elementStartDelay: workerConfiguration.elementStartDelay, + elementAddDelay: workerConfiguration.elementAddDelay, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion poolMaxSize: workerConfiguration.poolMaxSize!, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion