[project-history] log previous error when retrying createBlob operation (#23103)

GitOrigin-RevId: ff59d15e93c406e17775e5e4acac1f13da9a7788
This commit is contained in:
Jakob Ackermann
2025-01-24 11:32:12 +00:00
committed by Copybot
parent 5c3353b3de
commit 3b602ed93a
+20 -4
View File
@@ -1,3 +1,4 @@
import _ from 'lodash'
import async from 'async'
import logger from '@overleaf/logger'
import OError from '@overleaf/o-error'
@@ -37,6 +38,7 @@ export function createBlobsForUpdates(
let attempts = 0
// Since we may be creating O(1000) blobs in an update, allow for the
// occasional failure to prevent the whole update failing.
let lastErr
async.retry(
{
times: RETRY_ATTEMPTS,
@@ -46,14 +48,28 @@ export function createBlobsForUpdates(
attempts++
if (attempts > 1) {
logger.error(
{ projectId, doc: update.doc, file: update.file, attempts },
{
err: lastErr,
projectId,
historyId,
update: _.pick(
update,
'doc',
'file',
'hash',
'createdBlob',
'url'
),
attempts,
},
'previous createBlob attempt failed, retrying'
)
}
// extend the lock for each file because large files may take a long time
extendLock(err => {
if (err) {
return _cb(OError.tag(err))
lastErr = OError.tag(err)
return _cb(lastErr)
}
HistoryStoreManager.createBlobForUpdate(
projectId,
@@ -61,12 +77,12 @@ export function createBlobsForUpdates(
update,
(err, hashes) => {
if (err) {
OError.tag(err, 'retry: error creating blob', {
lastErr = OError.tag(err, 'retry: error creating blob', {
projectId,
doc: update.doc,
file: update.file,
})
_cb(err)
_cb(lastErr)
} else {
_cb(null, hashes)
}