summary refs log tree commit diff
diff options
context:
space:
mode:
authordank074 <torresefrain10@gmail.com>2026-01-30 20:26:50 -0600
committerdank074 <torresefrain10@gmail.com>2026-01-30 20:26:50 -0600
commit50d4ddbc02d69f030a472d724a4b188d7097ab92 (patch)
treec35af846dded7422f40a02cb2c4119cb613b9c5f
parentconvert event listener iterations to Promise.all + map (diff)
downloadserver-ts-50d4ddbc02d69f030a472d724a4b188d7097ab92.tar.xz
simplify reconnect delay and shorten time
-rw-r--r--src/util/util/RabbitMQ.ts13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/util/util/RabbitMQ.ts b/src/util/util/RabbitMQ.ts

index 1b09e29d..e60999d3 100644 --- a/src/util/util/RabbitMQ.ts +++ b/src/util/util/RabbitMQ.ts
@@ -30,8 +30,8 @@ export class RabbitMQ { // Reconnection state private static isReconnecting = false; private static reconnectAttempts = 0; - private static readonly MAX_RECONNECT_DELAY_MS = 30000; // Max 30 seconds between retries - private static readonly BASE_RECONNECT_DELAY_MS = 1000; // Start with 1 second + private static readonly MAX_RECONNECT_DELAY_MS = 5000; // Max 5 seconds between retries + private static readonly BASE_RECONNECT_DELAY_MS = 500; // Start with 500 milliseconds // Track if event listeners have been set up (to avoid duplicates) private static connectionListenersAttached = false; @@ -117,11 +117,10 @@ export class RabbitMQ { this.isReconnecting = true; this.reconnectAttempts++; - // Exponential backoff with jitter - const baseDelay = Math.min(this.BASE_RECONNECT_DELAY_MS * Math.pow(2, this.reconnectAttempts - 1), this.MAX_RECONNECT_DELAY_MS); - // Add jitter (±25%) to prevent thundering herd - const jitter = baseDelay * 0.25 * (Math.random() * 2 - 1); - const delay = Math.round(baseDelay + jitter); + // add random jitter to reconnection delay + const baseDelay = Math.min(this.BASE_RECONNECT_DELAY_MS + Math.random() * 2000, this.MAX_RECONNECT_DELAY_MS); + + const delay = Math.round(baseDelay); console.log(`[RabbitMQ] Scheduling reconnection attempt ${this.reconnectAttempts} in ${delay}ms`);