X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2FConfiguration.ts;h=cd3e0e8af807453cf6ef25b61f6539b5534c26e3;hb=1c818bd3b021c8e660d64f9054e02d06424a3c59;hp=dee8056c433d73c1a57c2670650cc913a1439fb6;hpb=ea32ea059bfdd7134abe2ba349985e5b15bc1d06;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index dee8056c..cd3e0e8a 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -21,7 +21,7 @@ import { type WorkerConfiguration } from '../types/index.js' import { - DEFAULT_ELEMENT_START_DELAY, + DEFAULT_ELEMENT_ADD_DELAY, DEFAULT_POOL_MAX_SIZE, DEFAULT_POOL_MIN_SIZE, DEFAULT_WORKER_START_DELAY, @@ -171,7 +171,7 @@ export class Configuration { if (isCFEnvironment()) { delete uiServerConfiguration.options?.host // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - uiServerConfiguration.options!.port = parseInt(env.PORT!) + uiServerConfiguration.options!.port = Number.parseInt(env.PORT!) } return uiServerConfiguration } @@ -275,10 +275,11 @@ export class Configuration { processType: WorkerProcessType.workerSet, startDelay: DEFAULT_WORKER_START_DELAY, elementsPerWorker: 'auto', - elementStartDelay: DEFAULT_ELEMENT_START_DELAY, + elementAddDelay: DEFAULT_ELEMENT_ADD_DELAY, poolMinSize: DEFAULT_POOL_MIN_SIZE, poolMaxSize: DEFAULT_POOL_MAX_SIZE } + const deprecatedWorkerConfiguration: WorkerConfiguration = { ...(hasOwnProp(Configuration.getConfigurationData(), 'workerProcess') && { processType: Configuration.getConfigurationData()?.workerProcess @@ -289,8 +290,11 @@ export class Configuration { ...(hasOwnProp(Configuration.getConfigurationData(), 'chargingStationsPerWorker') && { elementsPerWorker: Configuration.getConfigurationData()?.chargingStationsPerWorker }), - ...(hasOwnProp(Configuration.getConfigurationData(), 'elementStartDelay') && { - elementStartDelay: Configuration.getConfigurationData()?.elementStartDelay + ...(hasOwnProp(Configuration.getConfigurationData(), 'elementAddDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.elementAddDelay + }), + ...(hasOwnProp(Configuration.getConfigurationData()?.worker, 'elementStartDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.worker?.elementStartDelay }), ...(hasOwnProp(Configuration.getConfigurationData(), 'workerPoolMinSize') && { poolMinSize: Configuration.getConfigurationData()?.workerPoolMinSize @@ -396,9 +400,9 @@ export class Configuration { `Use '${ConfigurationSection.worker}' section to define the number of element(s) per worker instead` ) Configuration.warnDeprecatedConfigurationKey( - 'elementStartDelay', + 'elementAddDelay', undefined, - `Use '${ConfigurationSection.worker}' section to define the worker's element start delay instead` + `Use '${ConfigurationSection.worker}' section to define the worker's element add delay instead` ) Configuration.warnDeprecatedConfigurationKey( 'workerPoolMinSize', @@ -425,6 +429,11 @@ export class Configuration { ConfigurationSection.worker, 'Not publicly exposed to end users' ) + Configuration.warnDeprecatedConfigurationKey( + 'elementStartDelay', + ConfigurationSection.worker, + "Use 'elementAddDelay' instead" + ) if ( Configuration.getConfigurationData()?.worker?.processType === ('staticPool' as WorkerProcessType) @@ -504,22 +513,22 @@ export class Configuration { private static warnDeprecatedConfigurationKey ( key: string, - sectionName?: string, + configurationSection?: ConfigurationSection, logMsgToAppend = '' ): void { if ( - sectionName != null && - Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] != null && + configurationSection != null && + Configuration.getConfigurationData()?.[configurationSection as keyof ConfigurationData] != + null && ( - Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record< - string, - unknown - > + Configuration.getConfigurationData()?.[ + configurationSection as keyof ConfigurationData + ] as Record )[key] != null ) { console.error( `${chalk.green(logPrefix())} ${chalk.red( - `Deprecated configuration key '${key}' usage in section '${sectionName}'${ + `Deprecated configuration key '${key}' usage in section '${configurationSection}'${ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }` )}` @@ -535,7 +544,7 @@ export class Configuration { } } - private static getConfigurationData (): ConfigurationData | undefined { + public static getConfigurationData (): ConfigurationData | undefined { if (Configuration.configurationData == null) { try { Configuration.configurationData = JSON.parse(