import { fileURLToPath } from 'node:url'
import chalk from 'chalk'
-import { mergeDeepRight } from 'rambda'
+import { mergeDeepRight, once } from 'rambda'
import {
ApplicationProtocol,
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,
logPrefix
} from './ConfigurationUtils.js'
import { Constants } from './Constants.js'
-import { hasOwnProp, isCFEnvironment, once } from './Utils.js'
+import { hasOwnProp, isCFEnvironment } from './Utils.js'
type ConfigurationSectionType =
| LogConfiguration
public static getStationTemplateUrls (): StationTemplateUrl[] | undefined {
const checkDeprecatedConfigurationKeysOnce = once(
- Configuration.checkDeprecatedConfigurationKeys.bind(Configuration),
- Configuration
+ Configuration.checkDeprecatedConfigurationKeys.bind(Configuration)
)
checkDeprecatedConfigurationKeysOnce()
return Configuration.getConfigurationData()?.stationTemplateUrls
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
}
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
...(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
`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',
ConfigurationSection.worker,
'Not publicly exposed to end users'
)
+ Configuration.warnDeprecatedConfigurationKey(
+ 'elementStartDelay',
+ ConfigurationSection.worker,
+ "Use 'elementAddDelay' instead"
+ )
if (
Configuration.getConfigurationData()?.worker?.processType ===
('staticPool' as WorkerProcessType)
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<string, unknown>
)[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}` : ''
}`
)}`
}
}
- private static getConfigurationData (): ConfigurationData | undefined {
+ public static getConfigurationData (): ConfigurationData | undefined {
if (Configuration.configurationData == null) {
try {
Configuration.configurationData = JSON.parse(
event === 'change'
) {
Configuration.configurationFileReloading = true
- const consoleWarnOnce = once(console.warn, this)
+ const consoleWarnOnce = once(console.warn)
consoleWarnOnce(
`${chalk.green(logPrefix())} ${chalk.yellow(
`${FileType.Configuration} ${this.configurationFile} file have changed, reload`
Configuration.configurationSectionCache.clear()
if (Configuration.configurationChangeCallback != null) {
Configuration.configurationChangeCallback()
- .catch(error => {
+ .catch((error: unknown) => {
throw typeof error === 'string' ? new Error(error) : error
})
.finally(() => {