Skip to content

Commit

Permalink
DatalakeService include retry for object upload (#6807)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <[email protected]>
  • Loading branch information
BykhovDenis authored Oct 4, 2024
1 parent bb96ae4 commit 39cc7dc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions server/datalake/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 39cc7dc

Please sign in to comment.