2026-05-17 19:08:07 +08:00
|
|
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
|
|
|
|
import { Logger } from '@nestjs/common';
|
|
|
|
|
import { Job } from 'bullmq';
|
|
|
|
|
import { QUEUE_NOTIFICATION } from '../infrastructure/queue/queue.service';
|
|
|
|
|
import { NotificationsService } from '../modules/notifications/notifications.service';
|
2026-05-09 18:25:04 +08:00
|
|
|
|
2026-05-17 19:08:07 +08:00
|
|
|
@Processor(QUEUE_NOTIFICATION)
|
|
|
|
|
export class NotificationWorker extends WorkerHost {
|
|
|
|
|
private readonly logger = new Logger(NotificationWorker.name);
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly notificationsService: NotificationsService,
|
|
|
|
|
) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async process(job: Job<{ userId: string; type: string; title: string; body: string }>) {
|
|
|
|
|
this.logger.log(`Processing notification job ${job.id}`);
|
|
|
|
|
await this.notificationsService.send(job.data);
|
|
|
|
|
this.logger.log(`Notification job ${job.id} completed`);
|
|
|
|
|
}
|
|
|
|
|
}
|