UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

34 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BackoffConfig = void 0; class BackoffConfig { static setDefaultConfig(config) { this.config = this.parseConfig(config); return this.config; } static parseConfig(cfg = {}) { const config = Object.assign(Object.assign({}, this.config), cfg); const { baseDelay, maxDelay, jitter, maxAttempts } = config; if (baseDelay < this.config.baseDelay) { throw new Error(`baseDelay (${baseDelay}ms) is below minimum recommended (${this.config.baseDelay}ms)`); } if (maxDelay > this.config.maxDelay) { throw new Error(`maxDelay (${maxDelay}ms) exceeds maximum allowed (${this.config.maxDelay}ms)`); } if (baseDelay > maxDelay) { throw new Error(`baseDelay (${baseDelay}ms) cannot exceed maxDelay (${maxDelay}ms)`); } if (maxAttempts < 0) { throw new Error(`maxAttempts (${maxAttempts}) cannot be a negative integer`); } return { baseDelay, maxDelay, jitter, maxAttempts }; } } exports.BackoffConfig = BackoffConfig; BackoffConfig.config = { baseDelay: 1000, maxDelay: 60000, maxAttempts: 0, jitter: true, }; //# sourceMappingURL=backoff-config.js.map