Files
azuredatastudio/build/azure-pipelines/common/retry.js
Lewis Sanchez 6bd0a17d3c Merge from vscode merge-base (#22769)
* Merge from vscode merge-base

* Turn off basic checks

* Enable compilation, unit, and integration tests
2023-04-18 18:28:58 -07:00

29 lines
1.1 KiB
JavaScript

"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.retry = void 0;
async function retry(fn) {
let lastError;
for (let run = 1; run <= 10; run++) {
try {
return await fn();
}
catch (err) {
if (!/ECONNRESET|CredentialUnavailableError|Audience validation failed/i.test(err.message)) {
throw err;
}
lastError = err;
const millis = (Math.random() * 200) + (50 * Math.pow(1.5, run));
console.log(`Request failed, retrying in ${millis}ms...`);
// maximum delay is 10th retry: ~3 seconds
await new Promise(c => setTimeout(c, millis));
}
}
console.log(`Too many retries, aborting.`);
throw lastError;
}
exports.retry = retry;