From cb0efdfdaebdf8ac05fc1a0242e05fd457315f65 Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Tue, 26 May 2026 07:36:54 -0400 Subject: [PATCH] fix(proxy): export thumbnailQueue singleton for clean SIGTERM shutdown (issue #94 bug 7) --- services/worker/src/workers/proxy.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/worker/src/workers/proxy.js b/services/worker/src/workers/proxy.js index b4f6f7d..3d4c6ac 100644 --- a/services/worker/src/workers/proxy.js +++ b/services/worker/src/workers/proxy.js @@ -45,13 +45,16 @@ const IMAGE_CODECS = new Set([ const S3_BUCKET = process.env.S3_BUCKET || 'wild-dragon'; -// Dispatch thumbnail job once proxy is ready — same Redis connection as the worker +// BUG FIX #7: Keep thumbnailQueue as a module-level singleton so it is only +// opened once and can be closed during SIGTERM (via the exported closer). +// Previously a new Queue was created inside the worker function; BullMQ Queue +// instances hold an open Redis connection that prevents clean shutdown. const parseRedisUrl = (url) => { const parsed = new URL(url); return { host: parsed.hostname, port: parseInt(parsed.port, 10) }; }; -const thumbnailQueue = new Queue('thumbnail', { +export const thumbnailQueue = new Queue('thumbnail', { connection: parseRedisUrl(process.env.REDIS_URL || 'redis://queue:6379'), });