uberf-8304: retry fetch when updating ws info (#6757)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev
2024-09-27 23:49:24 +07:00
committed by GitHub
parent 7cb6c3a89a
commit 2f0223faad
2 changed files with 65 additions and 8 deletions
+24
View File
@@ -102,6 +102,30 @@ export async function getTransactorEndpoint (
}
}
export function withRetryUntilTimeout<P extends any[], T> (
f: (...params: P) => Promise<T>,
timeoutMs: number = 5000
): (...params: P) => Promise<T> {
return async function (...params: P): Promise<T> {
const timeout = Date.now() + timeoutMs
while (true) {
try {
return await f(...params)
} catch (err: any) {
if (timeout < Date.now()) {
// Timeout happened
throw err
}
if (err?.cause?.code === 'ECONNRESET' || err?.cause?.code === 'ECONNREFUSED') {
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
} else {
throw err
}
}
}
}
}
export async function getPendingWorkspace (
token: string,
region: string,