Просмотр исходного кода

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

GitOrigin-RevId: ff59d15e93c406e17775e5e4acac1f13da9a7788
Jakob Ackermann 1 год назад
Родитель
Сommit
3b602ed93a
1 измененных файлов с 20 добавлено и 4 удалено
  1. 20 4
      services/project-history/app/js/BlobManager.js

+ 20 - 4
services/project-history/app/js/BlobManager.js

@@ -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)
               }