api-server/src/workers/notification.worker.ts

23 lines
817 B
TypeScript
Raw Normal View History

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';
@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`);
}
}