retry createAsset sproc due to ECONNRESET

This commit is contained in:
João Moreno 2020-12-07 14:42:27 +01:00
parent c4d77ea619
commit 66aab34216

View file

@ -66,6 +66,20 @@ function getEnv(name: string): string {
return result;
}
async function retry<T>(fn: () => Promise<T>): Promise<T> {
for (let run = 1; run <= 10; run++) {
try {
return await fn();
} catch (err) {
if (!/ECONNRESET/.test(err.message)) {
throw err;
}
}
}
throw new Error('Retried too many times');
}
async function main(): Promise<void> {
const [, , platform, type, fileName, filePath] = process.argv;
const quality = getEnv('VSCODE_QUALITY');
@ -121,7 +135,7 @@ async function main(): Promise<void> {
const client = new CosmosClient({ endpoint: process.env['AZURE_DOCUMENTDB_ENDPOINT']!, key: process.env['AZURE_DOCUMENTDB_MASTERKEY'] });
const scripts = client.database('builds').container(quality).scripts;
await scripts.storedProcedure('createAsset').execute('', [commit, asset, true]);
await retry(() => scripts.storedProcedure('createAsset').execute('', [commit, asset, true]));
}
main().then(() => {