Merge pull request #21097 from overleaf/ls-scripts-to-esm-1

Migrate scripts folder to esm 1/x

GitOrigin-RevId: 4a4bc9a161f144fdb40ce3f2a0a9313b36c6df81
This commit is contained in:
Liangjun Song
2024-10-21 08:04:42 +00:00
committed by Copybot
parent 8bc374c916
commit 26f3f3e2e2
94 changed files with 916 additions and 847 deletions
@@ -1,9 +1,11 @@
const { ObjectId } = require('mongodb-legacy')
const {
import mongodb from 'mongodb-legacy'
import {
db,
waitForDb,
READ_PREFERENCE_SECONDARY,
} = require('../../app/src/infrastructure/mongodb')
} from '../../app/src/infrastructure/mongodb.js'
const { ObjectId } = mongodb
const ONE_MONTH_IN_MS = 1000 * 60 * 60 * 24 * 31
let ID_EDGE_PAST
@@ -195,7 +197,7 @@ function batchedUpdateWithResultHandling(
})
}
module.exports = {
export default {
batchedUpdate,
batchedUpdateWithResultHandling,
}
@@ -0,0 +1,31 @@
/**
* 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) {
if (
process.env.MONGO_SOCKET_TIMEOUT !== timeoutInMS.toString() ||
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]}`
)
}
}