chore: add loger for the telegram sender

This commit is contained in:
mahyargdz
2025-03-28 16:10:12 +03:30
parent cb9860853e
commit 0b62341908
13 changed files with 200 additions and 85 deletions
@@ -1,5 +1,4 @@
import { InjectQueue, Processor } from "@nestjs/bullmq";
import { Logger } from "@nestjs/common";
import { Job, Queue } from "bullmq";
import dayjs from "dayjs";
// eslint-disable-next-line import/no-named-as-default
@@ -7,6 +6,7 @@ import Decimal from "decimal.js";
import { DataSource, QueryRunner } from "typeorm";
import { WorkerProcessor } from "../../../common/queues/worker.processor";
import { LoggerService } from "../../logger/logger.service";
import { NotificationsService } from "../../notifications/providers/notifications.service";
import { SubscriptionStatus } from "../../subscriptions/enums/subscription-status.enum";
import { User } from "../../users/entities/user.entity";
@@ -16,21 +16,22 @@ import { Invoice } from "../entities/invoice.entity";
import { InvoiceStatus } from "../enums/invoice-status.enum";
import { InvoicesService } from "../providers/invoices.service";
@Processor(INVOICE.INVOICE_QUEUE_NAME)
@Processor(INVOICE.INVOICE_QUEUE_NAME, { concurrency: 5 })
export class InvoiceProcessor extends WorkerProcessor {
protected readonly logger = new Logger(InvoiceProcessor.name);
// protected readonly logger = new Logger(InvoiceProcessor.name);
constructor(
@InjectQueue(INVOICE.INVOICE_QUEUE_NAME) private readonly invoiceQueue: Queue,
private readonly invoicesService: InvoicesService,
private readonly dataSource: DataSource,
private readonly notificationService: NotificationsService,
protected readonly logger: LoggerService,
) {
super();
}
async process(job: Job, token?: string) {
this.logger.log(job, token);
this.logger.log(job);
switch (job.name) {
case INVOICE.INVOICE_REMINDER_JOB_NAME:
return this.sendBillInvoiceReminder(job, token);
@@ -234,7 +235,7 @@ export class InvoiceProcessor extends WorkerProcessor {
{
delay: INVOICE.INVOICE_REMINDER_REPEAT_DELAY, // 1 day delay in milliseconds
attempts: INVOICE.INVOICE_REMINDER_JOB_ATTEMPTS,
backoff: INVOICE.INVOICE_REMINDER_JOB_BACKOFF,
backoff: { type: "exponential", delay: INVOICE.INVOICE_REMINDER_JOB_BACKOFF },
},
);
}
@@ -261,7 +262,7 @@ export class InvoiceProcessor extends WorkerProcessor {
};
await Promise.all(
admins.map((admin) => this.notificationService.createRucurringInvoiceNotification(admin.id, notificationPayload, queryRunner)),
admins.map((admin) => this.notificationService.createRecurringInvoiceNotification(admin.id, notificationPayload, queryRunner)),
);
}
}