From 7d5827871dc39c5ee3618b608c293c0bbdb482ac Mon Sep 17 00:00:00 2001 From: jos3duardo Date: Mon, 11 Aug 2025 23:53:04 -0400 Subject: [PATCH] Refactor payment job handling to simplify retry logic and update job parameters --- src/modules/payments/cron/payments.cron.ts | 34 ---------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/modules/payments/cron/payments.cron.ts diff --git a/src/modules/payments/cron/payments.cron.ts b/src/modules/payments/cron/payments.cron.ts deleted file mode 100644 index bb5bcf6..0000000 --- a/src/modules/payments/cron/payments.cron.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Injectable, Logger } from '@nestjs/common'; -import { Cron } from '@nestjs/schedule'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Payment } from '../entities/payment.entity'; -import { In, Repository } from 'typeorm'; -import { PaymentStatusEnum } from '../enumns/payment-status.enum'; -import { ProcessPaymentService } from '../services/process-payment.service'; - -@Injectable() -export class PaymentsCron { - private readonly logger = new Logger(PaymentsCron.name); - - constructor( - @InjectRepository(Payment) - private readonly paymentRepository: Repository, - private processPaymentService: ProcessPaymentService, - ) {} - - @Cron('*/10 * * * * *') - async handleCron() { - const payments = await this.paymentRepository.find({ - where: { - status: In([PaymentStatusEnum.RETRY, PaymentStatusEnum.PROCESSING]), - attempts: In([1, 2, 3]), - }, - }); - - if (payments.length > 0) { - for (const payment of payments) { - await this.processPaymentService.execute(payment.id); - } - } - } -}