Implement BullMQ for background job processing

* new REDIS_URL environment variable
This commit is contained in:
Philipinho
2024-05-03 02:56:03 +01:00
parent 19a1f5e12d
commit 7f933addff
15 changed files with 314 additions and 6 deletions

View File

@ -0,0 +1 @@
export * from './queue.constants';

View File

@ -0,0 +1,7 @@
export enum QueueName {
EMAIL_QUEUE = '{email-queue}',
}
export enum QueueJob {
SEND_EMAIL = 'send-email',
}

View File

@ -0,0 +1,36 @@
import { Global, Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { EnvironmentService } from '../environment/environment.service';
import { parseRedisUrl } from '../../helpers';
import { QueueName } from './constants';
@Global()
@Module({
imports: [
BullModule.forRootAsync({
useFactory: (environmentService: EnvironmentService) => {
const redisConfig = parseRedisUrl(environmentService.getRedisUrl());
return {
connection: {
host: redisConfig.host,
port: redisConfig.port,
password: redisConfig.password,
},
defaultJobOptions: {
attempts: 3,
backoff: {
type: 'exponential',
delay: 10000,
},
},
};
},
inject: [EnvironmentService],
}),
BullModule.registerQueue({
name: QueueName.EMAIL_QUEUE,
}),
],
exports: [BullModule],
})
export class QueueModule {}