fix(proxy): export thumbnailQueue singleton for clean SIGTERM shutdown (issue #94 bug 7)

This commit is contained in:
Zac Gaetano 2026-05-26 07:36:54 -04:00
parent a6c9529c50
commit cb0efdfdae

View file

@ -45,13 +45,16 @@ const IMAGE_CODECS = new Set([
const S3_BUCKET = process.env.S3_BUCKET || 'wild-dragon'; 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 parseRedisUrl = (url) => {
const parsed = new URL(url); const parsed = new URL(url);
return { host: parsed.hostname, port: parseInt(parsed.port, 10) }; 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'), connection: parseRedisUrl(process.env.REDIS_URL || 'redis://queue:6379'),
}); });