Session 7b: Fix pipeline - body parser, Redis queueing, poller visibility, auto-start
This commit is contained in:
+10
-3
@@ -11,10 +11,13 @@ let degraded = false;
|
||||
function getRedisClient() {
|
||||
if (!client) {
|
||||
client = new Redis(process.env.REDIS_URL || 'redis://127.0.0.1:6379', {
|
||||
// Don't block the app starting up if Redis is down at boot. Failed
|
||||
// commands fall through to the cache-miss path immediately.
|
||||
// Eager connect — but allow commands to QUEUE while the TCP/auth
|
||||
// handshake completes. Without offline queueing, pollers booting
|
||||
// alongside the API throw "Stream isn't writeable" before Redis
|
||||
// is ready. With queueing, ioredis flushes the backlog the moment
|
||||
// the connection enters READY state.
|
||||
lazyConnect: false,
|
||||
enableOfflineQueue: false,
|
||||
enableOfflineQueue: true,
|
||||
maxRetriesPerRequest: 1,
|
||||
retryStrategy(times) {
|
||||
// Exponential backoff up to 30s. ioredis keeps trying forever on its
|
||||
@@ -30,7 +33,11 @@ function getRedisClient() {
|
||||
}
|
||||
});
|
||||
client.on('ready', () => {
|
||||
// Surface the ready transition in PM2/container logs so operators
|
||||
// can confirm the connection actually established. Distinct from
|
||||
// reconnect-after-outage which the line below logs at info.
|
||||
if (degraded) console.info('[redis] reconnected, leaving degraded mode');
|
||||
else console.log('[redis] connected and ready');
|
||||
degraded = false;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user