package.dist.src.config.retry.fixed-timeout-retry-strategy.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Client SDK for Momento services
The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedTimeoutRetryStrategy = void 0;
const storage_default_eligibility_strategy_1 = require("./storage-default-eligibility-strategy");
class FixedTimeoutRetryStrategy {
constructor(props) {
var _a, _b, _c;
this.logger = props.loggerFactory.getLogger(this);
this.eligibilityStrategy =
(_a = props.eligibilityStrategy) !== null && _a !== void 0 ? _a : new storage_default_eligibility_strategy_1.DefaultStorageEligibilityStrategy(props.loggerFactory);
this.retryDelayIntervalMillis = (_b = props.retryDelayIntervalMillis) !== null && _b !== void 0 ? _b : 100;
this.responseDataReceivedTimeoutMillis =
(_c = props.responseDataReceivedTimeoutMillis) !== null && _c !== void 0 ? _c : 1000;
}
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}`);
if (!this.eligibilityStrategy.isEligibleForRetry(props)) {
// null means do not retry
return null;
}
this.logger.debug(`Request is eligible for retry (attempt ${props.attemptNumber}), retrying after ${this.retryDelayIntervalMillis} ms +/- jitter.`);
// retry after a fixed time interval has passed (+/- some jitter)
return addJitter(this.retryDelayIntervalMillis);
}
}
exports.FixedTimeoutRetryStrategy = FixedTimeoutRetryStrategy;
function addJitter(whenToRetry) {
return (0.2 * Math.random() + 0.9) * whenToRetry;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4ZWQtdGltZW91dC1yZXRyeS1zdHJhdGVneS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWcvcmV0cnkvZml4ZWQtdGltZW91dC1yZXRyeS1zdHJhdGVneS50cyJdLCJuYW1lcyI6W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