fix(retry): address PR #15 code review feedback
- Re-export RETRY_BACKOFF_DELAYS and RETRY_JITTER_FACTOR from Defaults for backwards compatibility with existing imports - Add 'as const' to RETRY_JITTER_FACTOR for type consistency - Improve documentation explaining why values are hardcoded in retryConfigs (ESM initialization order issues with indirect circular imports)
This commit is contained in:
@@ -169,7 +169,6 @@ export const DEFAULT_CACHE_MAX_KEYS = {
|
|||||||
LID_GLOBAL: 10_000
|
LID_GLOBAL: 10_000
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: RETRY_BACKOFF_DELAYS and RETRY_JITTER_FACTOR are defined in retry-utils.ts
|
// Re-export retry constants for backwards compatibility
|
||||||
// to avoid circular dependency and initialization order issues.
|
// Actual definitions are in retry-utils.ts to avoid ESM initialization order issues
|
||||||
// Import from '@whiskeysockets/baileys' Utils if needed:
|
export { RETRY_BACKOFF_DELAYS, RETRY_JITTER_FACTOR } from '../Utils/retry-utils'
|
||||||
// import { getRetryDelayWithJitter, getAllRetryDelaysWithJitter } from './Utils/retry-utils'
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const RETRY_BACKOFF_DELAYS = [1000, 2000, 5000, 10000, 20000] as const
|
|||||||
* Jitter factor for retry delays (0.15 = ±15% randomization)
|
* Jitter factor for retry delays (0.15 = ±15% randomization)
|
||||||
* Helps prevent thundering herd problem
|
* Helps prevent thundering herd problem
|
||||||
*/
|
*/
|
||||||
export const RETRY_JITTER_FACTOR = 0.15
|
export const RETRY_JITTER_FACTOR = 0.15 as const
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backoff strategies
|
* Backoff strategies
|
||||||
@@ -656,14 +656,19 @@ export const retryConfigs = {
|
|||||||
/**
|
/**
|
||||||
* RSocket-style retry with stepped delays
|
* RSocket-style retry with stepped delays
|
||||||
* Uses fixed delay array: 1s, 2s, 5s, 10s, 20s (with ±15% jitter)
|
* Uses fixed delay array: 1s, 2s, 5s, 10s, 20s (with ±15% jitter)
|
||||||
* Values hardcoded to avoid initialization order issues in ESM
|
*
|
||||||
|
* NOTE: Values are hardcoded instead of referencing RETRY_BACKOFF_DELAYS/RETRY_JITTER_FACTOR
|
||||||
|
* to prevent "Cannot access before initialization" errors in ESM environments.
|
||||||
|
* This occurs when modules are loaded in specific orders due to indirect circular imports
|
||||||
|
* (e.g., via prometheus-metrics.ts -> circuit-breaker.ts chain).
|
||||||
|
* Keep these values in sync with the constants above (lines 25, 31).
|
||||||
*/
|
*/
|
||||||
rsocket: {
|
rsocket: {
|
||||||
maxAttempts: 5, // RETRY_BACKOFF_DELAYS.length
|
maxAttempts: 5, // = RETRY_BACKOFF_DELAYS.length
|
||||||
baseDelay: 1000, // RETRY_BACKOFF_DELAYS[0]
|
baseDelay: 1000, // = RETRY_BACKOFF_DELAYS[0]
|
||||||
maxDelay: 20000, // RETRY_BACKOFF_DELAYS[4]
|
maxDelay: 20000, // = RETRY_BACKOFF_DELAYS[4]
|
||||||
backoffStrategy: 'stepped' as const,
|
backoffStrategy: 'stepped' as const,
|
||||||
jitter: 0.15, // RETRY_JITTER_FACTOR
|
jitter: 0.15, // = RETRY_JITTER_FACTOR
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user