This commit is contained in:
Benjamin Pasero
2022-04-14 11:34:22 +02:00
committed by GitHub
parent 8b04a1acf9
commit ac6b490b2d
3 changed files with 44 additions and 25 deletions

View File

@@ -149,6 +149,21 @@ export function timeout(i: number) {
});
}
export async function retryWithRestart(app: Application, testFn: () => Promise<unknown>, retries = 3, timeoutMs = 20000): Promise<unknown> {
for (let i = 0; i < retries; i++) {
const result = await Promise.race([
testFn().then(() => true, error => { throw error; }),
timeout(timeoutMs).then(() => false)
]);
if (result) {
return;
}
await app.restart();
}
}
export interface ITask<T> {
(): T;
}