first commit
This commit is contained in:
12
services/web/scripts/helpers/chunkArray.mjs
Normal file
12
services/web/scripts/helpers/chunkArray.mjs
Normal file
@@ -0,0 +1,12 @@
|
||||
const CHUNK_SIZE = 1000
|
||||
|
||||
// Function to chunk the array
|
||||
export function chunkArray(array, size = CHUNK_SIZE) {
|
||||
const result = []
|
||||
for (let i = 0; i < array.length; i += size) {
|
||||
result.push(array.slice(i, i + size))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default { chunkArray }
|
32
services/web/scripts/helpers/env_variable_helper.mjs
Normal file
32
services/web/scripts/helpers/env_variable_helper.mjs
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Ensures that the specific MongoDB connection timeout is set.
|
||||
*
|
||||
* @param {number} timeoutInMS
|
||||
* @returns {void}
|
||||
*/
|
||||
export function ensureMongoTimeout(timeoutInMS) {
|
||||
if (process.env.MONGO_SOCKET_TIMEOUT !== timeoutInMS.toString()) {
|
||||
throw new Error(
|
||||
`must run with higher mongo timeout: MONGO_SOCKET_TIMEOUT=${timeoutInMS} node ${process.argv[1]}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures MongoDB queries are running on secondary and the specific connection timeout is set.
|
||||
*
|
||||
* @param {number} timeoutInMS
|
||||
* @returns {void}
|
||||
*/
|
||||
export function ensureRunningOnMongoSecondaryWithTimeout(timeoutInMS) {
|
||||
const timeout = parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 0
|
||||
if (
|
||||
timeout < timeoutInMS ||
|
||||
process.env.MONGO_CONNECTION_STRING !==
|
||||
process.env.READ_ONLY_MONGO_CONNECTION_STRING
|
||||
) {
|
||||
throw new Error(
|
||||
`must run on secondary with higher mongo timeout: MONGO_SOCKET_TIMEOUT=${timeoutInMS} MONGO_CONNECTION_STRING="$READ_ONLY_MONGO_CONNECTION_STRING" node ${process.argv[1]}`
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user