@atomist/automation-client
Version:
Atomist API for software low-level client
40 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const promiseRetry = require("promise-retry");
const logger_1 = require("./logger");
/**
* Default retry options for doWithRetry.
*/
exports.DefaultRetryOptions = {
retries: 5,
factor: 3,
minTimeout: 1 * 500,
maxTimeout: 5 * 1000,
randomize: true,
log: true,
};
/**
* Generic typed retry support
* Perform the task, retrying according to the retry options
* @param {() => Promise<R>} what
* @param {string} description
* @param {Object} opts
* @return {Promise<R>}
*/
function doWithRetry(what, description, opts = {}) {
const retryOptions = Object.assign(Object.assign({}, exports.DefaultRetryOptions), opts);
if (opts.log) {
logger_1.logger.log("silly", `${description} with retry options '%j'`, retryOptions);
}
return promiseRetry(retryOptions, retry => {
return what()
.catch(err => {
if (opts.log) {
logger_1.logger.warn(`Error occurred attempting '${description}': ${err.message}`);
}
retry(err);
});
});
}
exports.doWithRetry = doWithRetry;
//# sourceMappingURL=retry.js.map