X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FConfiguration.ts;h=86c9335802bfc1a19eb4c11e10ab074a4ab22dbc;hb=f902e1c441c6751f885e39bc5aa23721a102f424;hp=b1bc6e3adbe4a6662a37a902fb30ba4ca31af656;hpb=2dcfe98ec940932372855643f996b87c27f4b7fa;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index b1bc6e3a..86c93358 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -1,13 +1,13 @@ import ConfigurationData, { StationTemplateUrl, StorageConfiguration, SupervisionUrlDistribution, UIWebSocketServerConfiguration } from '../types/ConfigurationData'; import Constants from './Constants'; +import { HandleErrorParams } from '../types/Error'; import { ServerOptions } from 'ws'; import { StorageType } from '../types/Storage'; import type { WorkerChoiceStrategy } from 'poolifier'; import { WorkerProcessType } from '../types/Worker'; import chalk from 'chalk'; import fs from 'fs'; -import { level } from 'winston'; import path from 'path'; export default class Configuration { @@ -103,6 +103,10 @@ export default class Configuration { return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerStartDelay') ? Configuration.getConfig().workerStartDelay : Constants.WORKER_START_DELAY; } + static getElementStartDelay(): number { + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'elementStartDelay') ? Configuration.getConfig().elementStartDelay : Constants.ELEMENT_START_DELAY; + } + static getWorkerPoolMinSize(): number { return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : Constants.DEFAULT_WORKER_POOL_MIN_SIZE; } @@ -137,8 +141,8 @@ export default class Configuration { return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') ? Configuration.getConfig().logMaxFiles : 7; } - static getLogLevel(): level { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logLevel') ? Configuration.getConfig().logLevel.toLowerCase() as level : 'info'; + static getLogLevel(): string { + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logLevel') ? Configuration.getConfig().logLevel.toLowerCase() : 'info'; } static getLogFile(): string { @@ -229,7 +233,7 @@ export default class Configuration { return typeof obj === 'undefined'; } - private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException): void { + private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException, params: HandleErrorParams = { throwError: true }): void { const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : ''; if (error.code === 'ENOENT') { console.error(chalk.green(prefix) + chalk.red(fileType + ' file ' + filePath + ' not found: '), error); @@ -240,6 +244,8 @@ export default class Configuration { } else { console.error(chalk.green(prefix) + chalk.red(fileType + ' file ' + filePath + ' error: '), error); } - throw error; + if (params?.throwError) { + throw error; + } } }