fix: Added bullmq
This commit is contained in:
@@ -6,6 +6,8 @@ import { AuthGuard } from './guards/auth.guard';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { RequestContextModule } from 'core/als/request-context.module';
|
||||
import { BullModule } from '@nestjs/bullmq';
|
||||
import { Queue } from 'bullmq';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@@ -18,6 +20,9 @@ import { RequestContextModule } from 'core/als/request-context.module';
|
||||
],
|
||||
controllers: [AuthController],
|
||||
imports: [
|
||||
BullModule.registerQueue({
|
||||
name: "mail"
|
||||
}),
|
||||
UserModule,
|
||||
JwtModule,
|
||||
RequestContextModule,
|
||||
|
||||
@@ -5,7 +5,8 @@ import * as bcrypt from 'bcrypt';
|
||||
import { UserService } from 'src/user/user.service';
|
||||
import { TokenInputType } from './types';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { Queue } from 'bullmq';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
|
||||
@Injectable()
|
||||
@Public()
|
||||
@@ -13,7 +14,7 @@ export class AuthService {
|
||||
constructor(
|
||||
private readonly userService: UserService,
|
||||
private readonly jwtService: JwtService,
|
||||
private readonly eventEmitter: EventEmitter2
|
||||
@InjectQueue('mail') private readonly mailQueue: Queue
|
||||
) { }
|
||||
|
||||
async register(dto: RegisterUserRequestDTO) {
|
||||
@@ -23,7 +24,17 @@ export class AuthService {
|
||||
password: hashedPassword,
|
||||
});
|
||||
|
||||
this.eventEmitter.emit('user.sign_up', dto.email)
|
||||
this.mailQueue.add('send-welcome-email', {
|
||||
email: dto.email
|
||||
}, {
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
type: "exponential",
|
||||
delay: 3000,
|
||||
},
|
||||
removeOnComplete: true, // clean up Redis after success
|
||||
removeOnFail: false,
|
||||
})
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user