UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

33 lines 1.19 kB
export class BackoffConfig { static config = { baseDelay: 1000, maxDelay: 60_000, maxAttempts: 0, jitter: true, }; static setDefaultConfig(config) { this.config = this.parseConfig(config); return this.config; } static parseConfig(cfg = {}) { const config = { ...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 }; } } //# sourceMappingURL=backoff-config.js.map