Merge pull request #13362 from overleaf/csh-issue-13004-Always-Retry-during-GCS-delete

Always retry during GCS delete in history-v1 cron

GitOrigin-RevId: 1b64133dd0b9982f18124d9baa6e29bcdf6fa1f3
This commit is contained in:
Christopher Hoskin 2023-06-07 14:30:46 +01:00 committed by Copybot
parent 5fdc43e342
commit cc35bf4447
2 changed files with 20 additions and 3 deletions

View file

@ -1,11 +1,12 @@
const fs = require('fs')
const { pipeline } = require('stream/promises')
const { PassThrough } = require('stream')
const { Storage } = require('@google-cloud/storage')
const { Storage, IdempotencyStrategy } = require('@google-cloud/storage')
const { WriteError, ReadError, NotFoundError } = require('./Errors')
const asyncPool = require('tiny-async-pool')
const AbstractPersistor = require('./AbstractPersistor')
const PersistorHelper = require('./PersistorHelper')
const Logger = require('@overleaf/logger')
module.exports = class GcsPersistor extends AbstractPersistor {
constructor(settings) {
@ -20,7 +21,22 @@ module.exports = class GcsPersistor extends AbstractPersistor {
storageOptions.projectId = this.settings.endpoint.projectId
storageOptions.apiEndpoint = this.settings.endpoint.apiEndpoint
}
storageOptions.retryOptions = this.settings.retryOptions
storageOptions.retryOptions = { ...this.settings.retryOptions }
if (storageOptions.retryOptions) {
if (storageOptions.retryOptions.idempotencyStrategy) {
const value =
IdempotencyStrategy[this.settings.retryOptions.idempotencyStrategy]
if (value === undefined) {
throw new Error(
'Unrecognised value for retryOptions.idempotencyStrategy'
)
}
Logger.info(
`Setting retryOptions.idempotencyStrategy to ${storageOptions.retryOptions.idempotencyStrategy} (${value})`
)
storageOptions.retryOptions.idempotencyStrategy = value
}
}
this.storage = new Storage(storageOptions)
}

View file

@ -21,7 +21,8 @@
"projectId": "GCS_PROJECT_ID"
},
"retryOptions": {
"maxRetries": "GCS_MAX_RETRIES"
"maxRetries": "GCS_MAX_RETRIES",
"idempotencyStrategy": "GCS_IDEMPOTENCY_STRATEGY"
}
},
"fallback": {