mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #3118 from overleaf/jpa-delay-mongo-connection-use
[scripts] batchedUpdate: try to work around flaky mongo connection setup GitOrigin-RevId: 2bba7117b8f8892a41703569fef3f97d5e8d6835
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { promisify } = require('util')
|
||||
const { ReadPreference } = require('mongodb')
|
||||
const { getNativeDb } = require('../../app/src/infrastructure/Mongoose')
|
||||
|
||||
@@ -21,6 +22,12 @@ async function performUpdate(collection, nextBatch, update) {
|
||||
}
|
||||
|
||||
async function batchedUpdate(collectionName, query, update) {
|
||||
// Apparently the mongo driver returns the connection too early.
|
||||
// Some secondary connections are not ready as it returns, leading to
|
||||
// failing cursor actions with a readPreference set to 'secondary'.
|
||||
// TODO(das7pad): revisit/remove this delay after the mongo-driver update.
|
||||
await Promise.all([getNativeDb(), promisify(setTimeout)(10 * 1000)])
|
||||
|
||||
const db = await getNativeDb()
|
||||
const collection = db.collection(collectionName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user