more stuff

This commit is contained in:
Boki 2026-10-20 20:11:40 -04:00
parent c3cb36c8d6
commit 7dec0be3b4
26 changed files with 1394 additions and 275 deletions

View file

@ -73,8 +73,8 @@ export function registerApplicationServices(
db: config.redis.db,
},
defaultQueueOptions: {
workers: defined(config.queue).workers || 1,
concurrency: defined(config.queue).concurrency || 1,
workers: defined(config.queue).workers ?? 1,
concurrency: defined(config.queue).concurrency ?? 1,
defaultJobOptions: defined(config.queue).defaultJobOptions,
},
enableScheduledJobs: defined(config.queue).enableScheduledJobs ?? true,

View file

@ -554,8 +554,8 @@ export class QueueManager {
}
}
const workerCount = this.config.defaultQueueOptions?.workers || 1;
const concurrency = this.config.defaultQueueOptions?.concurrency || 1;
const workerCount = this.config.defaultQueueOptions?.workers ?? 1;
const concurrency = this.config.defaultQueueOptions?.concurrency ?? 1;
if (workerCount > 0) {
queue.startWorkersManually(workerCount, concurrency);

View file

@ -56,7 +56,8 @@ export class Queue {
// Initialize BullMQ queue
this.bullQueue = new BullQueue(queueName, {
connection,
// Publishing must fail promptly during outages; durable producers retain their intent.
connection: { ...connection, maxRetriesPerRequest: 1, enableOfflineQueue: false },
defaultJobOptions: {
removeOnComplete: 100,
removeOnFail: 100,
@ -68,6 +69,9 @@ export class Queue {
...defaultJobOptions,
},
});
this.bullQueue.on('error', error =>
this.logger.error('Queue connection error', { queueName, error })
);
// Initialize queue events if workers will be used
if (config.workers && config.workers > 0) {

View file

@ -1,39 +1,14 @@
import type { RedisConfig } from './types';
/**
* Get Redis connection configuration with retry settings
*/
/** Honor the explicit endpoint, including isolated test Redis instances. */
export function getRedisConnection(config: RedisConfig) {
const isTest = process.env.NODE_ENV === 'test' || process.env['BUNIT'] === '1';
// In test mode, always use localhost
const testConfig = isTest
? {
host: 'localhost',
port: 6379,
}
: config;
const baseConfig = {
host: testConfig.host,
port: testConfig.port,
password: testConfig.password,
db: testConfig.db,
maxRetriesPerRequest: null, // Required by BullMQ
return {
...config,
maxRetriesPerRequest: null, // Workers must survive transient outages.
enableReadyCheck: false,
connectTimeout: isTest ? 1000 : 3000,
lazyConnect: false, // Changed from true to ensure connection is established immediately
keepAlive: true, // Changed from false to maintain persistent connections
retryStrategy: (times: number) => {
const maxRetries = isTest ? 1 : 3;
if (times > maxRetries) {
return null; // Stop retrying
}
const delay = isTest ? 100 : Math.min(times * 100, 3000);
return delay;
},
connectTimeout: 3000,
lazyConnect: false,
keepAlive: 10000,
retryStrategy: (times: number) => Math.min(times * 100, 3000),
};
// In non-test mode, spread config first to preserve additional properties, then override with our settings
return isTest ? baseConfig : { ...config, ...baseConfig };
}

View file

@ -17,6 +17,8 @@ export interface JobData<T = unknown> {
* Queue job options
*/
export interface JobOptions {
/** Stable identity for idempotent publication (BullMQ IDs cannot contain colons). */
jobId?: string;
priority?: number;
delay?: number;
attempts?: number;