UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const promiseRetry = require("promise-retry");
4const logger_1 = require("../internal/util/logger");
5/**
6 * Default retry options for doWithRetry.
7 */
8exports.DefaultRetryOptions = {
9 retries: 5,
10 factor: 3,
11 minTimeout: 1 * 500,
12 maxTimeout: 5 * 1000,
13 randomize: true,
14};
15/**
16 * Generic typed retry support
17 * Perform the task, retrying according to the retry options
18 * @param {() => Promise<R>} what
19 * @param {string} description
20 * @param {Object} opts
21 * @return {Promise<R>}
22 */
23function doWithRetry(what, description, opts = {}) {
24 const retryOptions = Object.assign({}, exports.DefaultRetryOptions, opts);
25 logger_1.logger.debug(`${description} with retry options '%j'`, retryOptions);
26 return promiseRetry(retryOptions, retry => {
27 return what()
28 .catch(err => {
29 logger_1.logger.warn(`Error occurred attempting '${description}': ${err.message}`);
30 retry(err);
31 });
32 });
33}
34exports.doWithRetry = doWithRetry;
35//# sourceMappingURL=retry.js.map
\No newline at end of file