Merge pull request #5888 from overleaf/tm-history-upgrade-improve-logging

Prevent unnecessary extra batch, and add a 'continueFrom' helper for BATCH_LAST_ID

GitOrigin-RevId: d6832c40bbed2c27676f4b72d720938707847bfc
This commit is contained in:
Eric Mc Sween 2021-11-23 10:00:59 -05:00 committed by Copybot
parent 9cf622e013
commit bcd64d333f

View file

@ -33,11 +33,22 @@ const RESULT = {
attempted: 0,
projectsUpgraded: 0,
failed: 0,
continueFrom: null,
}
let INTERRUPT = false
async function processBatch(_, projects) {
if (projects.length && projects[0]._id) {
RESULT.continueFrom = projects[0]._id
}
await promiseMapWithLimit(WRITE_CONCURRENCY, projects, processProject)
console.log(RESULT)
if (INTERRUPT) {
// ctrl+c
console.log('Terminated by SIGINT')
process.exit(0)
}
if (RESULT.failed >= MAX_FAILURES) {
console.log(`MAX_FAILURES limit (${MAX_FAILURES}) reached. Stopping.`)
process.exit(0)
@ -47,14 +58,6 @@ async function processBatch(_, projects) {
`MAX_UPGRADES_TO_ATTEMPT limit (${MAX_UPGRADES_TO_ATTEMPT}) reached. Stopping.`
)
process.exit(0)
} else {
await promiseMapWithLimit(WRITE_CONCURRENCY, projects, processProject)
console.log(RESULT)
if (INTERRUPT) {
// ctrl+c
console.log('Terminated by SIGINT')
process.exit(0)
}
}
}