Merge pull request #5751 from overleaf/tm-history-upgrade-max-failures

Add configurable limit for number of failures (stop when reached)

GitOrigin-RevId: 56f0bf1d2e803851d68918b26f06d3b5834d7cc0
This commit is contained in:
Thomas 2021-11-11 16:09:41 +01:00 committed by Copybot
parent b7e9f0b67f
commit ec36fe4b04

View file

@ -5,6 +5,7 @@ const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 100
const DRY_RUN = process.env.DRY_RUN !== 'false' const DRY_RUN = process.env.DRY_RUN !== 'false'
const MAX_UPGRADES_TO_ATTEMPT = const MAX_UPGRADES_TO_ATTEMPT =
parseInt(process.env.MAX_UPGRADES_TO_ATTEMPT, 10) || false parseInt(process.env.MAX_UPGRADES_TO_ATTEMPT, 10) || false
const MAX_FAILURES = parseInt(process.env.MAX_FAILURES, 10) || 50
// persist fallback in order to keep batchedUpdate in-sync // persist fallback in order to keep batchedUpdate in-sync
process.env.BATCH_SIZE = BATCH_SIZE process.env.BATCH_SIZE = BATCH_SIZE
// raise mongo timeout to 1hr if otherwise unspecified // raise mongo timeout to 1hr if otherwise unspecified
@ -24,6 +25,7 @@ console.log({
WRITE_CONCURRENCY, WRITE_CONCURRENCY,
BATCH_SIZE, BATCH_SIZE,
MAX_UPGRADES_TO_ATTEMPT, MAX_UPGRADES_TO_ATTEMPT,
MAX_FAILURES,
}) })
const RESULT = { const RESULT = {
@ -36,6 +38,10 @@ const RESULT = {
let INTERRUPT = false let INTERRUPT = false
async function processBatch(_, projects) { async function processBatch(_, projects) {
if (RESULT.failed >= MAX_FAILURES) {
console.log(`MAX_FAILURES limit (${MAX_FAILURES}) reached. Stopping.`)
process.exit(0)
}
if (MAX_UPGRADES_TO_ATTEMPT && RESULT.attempted >= MAX_UPGRADES_TO_ATTEMPT) { if (MAX_UPGRADES_TO_ATTEMPT && RESULT.attempted >= MAX_UPGRADES_TO_ATTEMPT) {
console.log( console.log(
`MAX_UPGRADES_TO_ATTEMPT limit (${MAX_UPGRADES_TO_ATTEMPT}) reached. Stopping.` `MAX_UPGRADES_TO_ATTEMPT limit (${MAX_UPGRADES_TO_ATTEMPT}) reached. Stopping.`
@ -68,11 +74,13 @@ async function processProject(project) {
} }
async function doUpgradeForNoneWithoutConversion(project) { async function doUpgradeForNoneWithoutConversion(project) {
if (RESULT.failed >= MAX_FAILURES) {
return
}
if (MAX_UPGRADES_TO_ATTEMPT && RESULT.attempted >= MAX_UPGRADES_TO_ATTEMPT) { if (MAX_UPGRADES_TO_ATTEMPT && RESULT.attempted >= MAX_UPGRADES_TO_ATTEMPT) {
return return
} else {
RESULT.attempted += 1
} }
RESULT.attempted += 1
const projectId = project._id const projectId = project._id
if (!DRY_RUN) { if (!DRY_RUN) {
// ensureHistoryExistsForProject resyncs project // ensureHistoryExistsForProject resyncs project