notification queue

This commit is contained in:
2025-12-14 10:13:34 +03:30
parent befa311e98
commit b7e41ff67d
8 changed files with 109 additions and 210 deletions
@@ -2,7 +2,11 @@ import { Injectable, Logger } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { NotificationQueueNameEnum } from '../constants/queue';
import { PushNotificationQueueJob, SmsNotificationQueueJob } from '../interfaces/jobs-queue.interface';
import {
InAppNotificationQueueJob,
PushNotificationQueueJob,
SmsNotificationQueueJob,
} from '../interfaces/jobs-queue.interface';
@Injectable()
export class NotificationQueueService {
@@ -11,6 +15,7 @@ export class NotificationQueueService {
constructor(
@InjectQueue(NotificationQueueNameEnum.SMS) private readonly smsQueue: Queue,
@InjectQueue(NotificationQueueNameEnum.PUSH) private readonly pushQueue: Queue,
@InjectQueue(NotificationQueueNameEnum.IN_APP) private readonly inAppQueue: Queue,
) {}
async addSmsNotification(job: SmsNotificationQueueJob): Promise<void> {
@@ -112,4 +117,26 @@ export class NotificationQueueService {
throw error;
}
}
async addBulkInAppNotifications(jobs: InAppNotificationQueueJob[]): Promise<void> {
try {
const queueJobs = jobs.map(job => ({
name: 'in-app-notification',
data: job,
opts: {
jobId: `${job.subject}-${job.notificationId}-${Date.now()}`,
attempts: 3,
backoff: {
type: 'exponential',
delay: 2000,
},
},
}));
await this.inAppQueue.addBulk(queueJobs);
this.logger.log(`Added ${jobs.length} InApp notification jobs to queue`);
} catch (error) {
this.logger.error(`Failed to add bulk notifications to queue:`, error);
throw error;
}
}
}