All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.config.retry.fixed-count-retry-strategy.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedCountRetryStrategy = void 0;
const default_eligibility_strategy_1 = require("./default-eligibility-strategy");
class FixedCountRetryStrategy {
    constructor(props) {
        var _a;
        this.logger = props.loggerFactory.getLogger(this);
        this.eligibilityStrategy =
            (_a = props.eligibilityStrategy) !== null && _a !== void 0 ? _a : new default_eligibility_strategy_1.DefaultEligibilityStrategy(props.loggerFactory);
        this.maxAttempts = props.maxAttempts;
    }
    determineWhenToRetryRequest(props) {
        this.logger.debug(`Determining whether request is eligible for retry; status code: ${props.grpcStatus.code}, request type: ${props.grpcRequest.path}, attemptNumber: ${props.attemptNumber}, maxAttempts: ${this.maxAttempts}`);
        if (!this.eligibilityStrategy.isEligibleForRetry(props)) {
            // null means do not retry
            return null;
        }
        if (props.attemptNumber > this.maxAttempts) {
            this.logger.debug(`Exceeded max attempt count (${this.maxAttempts})`);
            // null means do not retry
            return null;
        }
        this.logger.debug(`Request is eligible for retry (attempt ${props.attemptNumber} of ${this.maxAttempts}, retrying immediately.`);
        // 0 means retry immediately
        return 0;
    }
}
exports.FixedCountRetryStrategy = FixedCountRetryStrategy;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4ZWQtY291bnQtcmV0cnktc3RyYXRlZ3kuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29uZmlnL3JldHJ5L2ZpeGVkLWNvdW50LXJldHJ5LXN0cmF0ZWd5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUtBLGlGQUEwRTtBQVMxRSxNQUFhLHVCQUF1QjtJQUtsQyxZQUFZLEtBQW1DOztRQUM3QyxJQUFJLENBQUMsTUFBTSxHQUFHLEtBQUssQ0FBQyxhQUFhLENBQUMsU0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