DatalakeService include retry for object upload (#6807)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-10-04 21:30:57 +05:00 committed by GitHub
parent bb96ae4b1c
commit 39cc7dc280
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -127,8 +127,10 @@ export class DatalakeService implements StorageAdapter {
size
}
await ctx.with('put', {}, async () => {
return await this.client.putObject(ctx, workspaceId, objectName, stream, metadata)
await ctx.with('put', {}, async (ctx) => {
await withRetry(ctx, 5, async () => {
return await this.client.putObject(ctx, workspaceId, objectName, stream, metadata)
})
})
return {
@ -187,3 +189,25 @@ export function processConfigFromEnv (storageConfig: StorageConfiguration): stri
storageConfig.storages.push(config)
storageConfig.default = 'datalake'
}
async function withRetry<T> (
ctx: MeasureContext,
retries: number,
op: () => Promise<T>,
delay: number = 100
): Promise<T> {
let error: any
while (retries > 0) {
retries--
try {
return await op()
} catch (err: any) {
error = err
ctx.error('error', { err })
if (retries !== 0) {
await new Promise((resolve) => setTimeout(resolve, delay))
}
}
}
throw error
}