import { BullModuleOptions, SharedBullConfigurationFactory } from '@nestjs/bull'; import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; /** * Bull Queue Configuration * Configures Redis connection and queue settings for Bull */ @Injectable() export class BullConfigService implements SharedBullConfigurationFactory { constructor(private configService: ConfigService) {} createSharedConfiguration(): BullModuleOptions { return { redis: { host: '43.205.35.45', port: 6379, password: 'Rezolut123', db: 0, // Enable offline queue to handle Redis disconnections enableOfflineQueue: true, // Retry strategy for Redis connection retryStrategy: (times: number) => { const delay = Math.min(times * 50, 2000); return delay; }, // Connection timeout connectTimeout: 10000, // Keep alive settings keepAlive: 30000, }, // Default job options for all queues defaultJobOptions: { attempts: 3, backoff: { type: 'exponential', delay: 5000, }, removeOnComplete: { age: 3600 * 24 * 7, // Keep completed jobs for 7 days count: 1000, // Keep max 1000 completed jobs }, removeOnFail: { age: 3600 * 24 * 30, // Keep failed jobs for 30 days }, }, // Queue settings settings: { // Stalled job checking interval stalledInterval: 30000, // Maximum stalled count before job is considered failed maxStalledCount: 2, // Lock duration for jobs lockDuration: 300000, // 5 minutes // Lock renew time lockRenewTime: 150000, // 2.5 minutes }, // Prefix for all queue keys in Redis prefix: 'bull', }; } } /** * Factory function for BullModule.forRootAsync() */ export const bullConfigFactory = { useClass: BullConfigService, };