Skip to content

Commit

Permalink
fixing some errors and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samehajala committed Dec 28, 2024
1 parent 7c9fc21 commit 1d13ed1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean cancelPayment(UUID paymentId) {
Payment payment = paymentRepository.findById(paymentId);
if (payment != null && payment.getPaymentStatus() == PaymentStatus.PENDING) {
payment.setPaymentStatus(PaymentStatus.FAILED);
paymentRepository.savePayment(payment);
paymentRepository.updatePayment(payment);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public class PaymentOutBoxProcessorImpl implements PaymentOutBoxProcessor {
BankClient bankClient;

@Override
@Retry(maxRetries = 2, delay = 500, jitter = 200) // Retry mechanism for failures
@Timeout(500) // Timeout after 1 second
@Retry(delay = 1000, maxRetries = 3) // Retry mechanism for failures
@Timeout(1000) // 1s is the time out
public Response processPaymentWithRetry(BankPaymentRequest request) {
return bankClient.makeNewPayment(request);
}
int i = 0 ;
@Override
@Scheduled(every = "10s")
@Transactional(Transactional.TxType.REQUIRES_NEW)
@Transactional
public void processOutboxEvents() {
List<PaymentOutBox> unprocessedEvents = boxRepository.findUnprocessedEvents();
int maxEventsToProcess = 200;
Expand All @@ -57,9 +57,7 @@ public void processOutboxEvents() {
for (PaymentOutBox event : unprocessedEvents) {
if (processedCount >= maxEventsToProcess) {
i++ ;
System.out.println("oppa 33la sel3t oropa"+i);


System.out.println("rate limiter"+i);
break; // Exit loop if we have processed the maximum number of events
}
JsonObject payloadJson = Json.createReader(new StringReader(event.getPayload())).readObject();
Expand Down Expand Up @@ -87,30 +85,20 @@ public void processOutboxEvents() {
cardNumber,
cardCode
);

// Process the payment with retry and timeout mechanisms
Response response = processPaymentWithRetry(bankPaymentRequest);

if (response.getStatus() == Response.Status.OK.getStatusCode()) {
paymentService.completePayment(payment.getPaymentId());
}
else if (response.getStatus() == Response.Status.CONFLICT.getStatusCode()) {
paymentService.cancelPayment(payment.getPaymentId()) ;
System.out.println("oooooh ya 3alm");
} else {
paymentService.cancelPayment(payment.getPaymentId());
}

// Mark the event as processed
event.setProcessed(true);
boxRepository.update(event);
processedCount++;

} catch (Exception e) {
System.err.println("Error processing payment: " + e.getMessage());

paymentService.cancelPayment(event.getPaymentId());
event.setProcessed(true);
boxRepository.update(event);
System.out.println(e);
processedCount++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion payment/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ quarkus.rate-limiter.buckets.group1.limits[0].period: 1S
# fair use
quarkus.rate-limiter.buckets.group1.limits[1].permitted-uses: 100
quarkus.rate-limiter.buckets.group1.limits[1].period: 5M
quarkus.transaction-manager.default-transaction-timeout=120




Expand Down

0 comments on commit 1d13ed1

Please sign in to comment.