UNPKG

@mdf.js/tasks

Version:

MMS - API Core - Tasks

69 lines 2.7 kB
"use strict"; /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryManager = void 0; const tslib_1 = require("tslib"); const ms_1 = tslib_1.__importDefault(require("ms")); const _1 = require("."); class RetryManager { /** * Create a retry manager * @param limiterDelay - Limiter delay * @param pollingGroup - Polling group * @param logger - Logger */ constructor(limiterDelay, pollingGroup, logger) { this.limiterDelay = limiterDelay; this.pollingGroup = pollingGroup; this.logger = logger; } /** * Fast cycle retry options * @param options - Task options * @returns Task options with fast cycle retry options */ fastCycleRetryOptions(options) { var _a, _b; const attempts = Math.min(_1.DEFAULT_MAX_RETRY_FACTOR, (_b = (_a = options.retryOptions) === null || _a === void 0 ? void 0 : _a.attempts) !== null && _b !== void 0 ? _b : 1); return this.cycleRetryOptions(options, attempts); } /** * Slow cycle retry options * @param options - Task options * @returns Task options with slow cycle retry options */ slowCycleRetryOptions(options) { return this.cycleRetryOptions(options, 1); } /** * Cycle retry options * @param options - Task options * @param attempts - Number of attempts * @returns Task options with cycle retry options */ cycleRetryOptions(options, attempts) { var _a, _b, _c, _d, _e, _f; const timeout = Math.min((_b = (_a = options.retryOptions) === null || _a === void 0 ? void 0 : _a.timeout) !== null && _b !== void 0 ? _b : _1.DEFAULT_MAX_TIMEOUT, (0, ms_1.default)(this.pollingGroup) * attempts); const waitTime = Math.min((_d = (_c = options.retryOptions) === null || _c === void 0 ? void 0 : _c.waitTime) !== null && _d !== void 0 ? _d : this.limiterDelay, this.limiterDelay); const retryOptions = { logger: this.logger.crash, attempts, timeout, waitTime, maxWaitTime: waitTime, interrupt: (_e = options.retryOptions) === null || _e === void 0 ? void 0 : _e.interrupt, abortSignal: (_f = options.retryOptions) === null || _f === void 0 ? void 0 : _f.abortSignal, }; return { ...options, retryOptions, }; } } exports.RetryManager = RetryManager; //# sourceMappingURL=RetryManager.js.map