0
0
Fork 0

Streaming: Refactor move database and redis logic into separate files (#31567)

This commit is contained in:
Emelia Smith 2024-08-27 10:40:04 +02:00 committed by GitHub
parent a7f8417795
commit 4118688fba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 219 additions and 195 deletions

View file

@ -59,3 +59,23 @@ export function firstParam(arrayOrString) {
return arrayOrString;
}
}
/**
* Takes an environment variable that should be an integer, attempts to parse
* it falling back to a default if not set, and handles errors parsing.
* @param {string|undefined} value
* @param {number} defaultValue
* @param {string} variableName
* @returns {number}
*/
export function parseIntFromEnvValue(value, defaultValue, variableName) {
if (typeof value === 'string' && value.length > 0) {
const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
throw new Error(`Invalid ${variableName} environment variable: ${value}`);
}
return parsedValue;
} else {
return defaultValue;
}
}