Skip to content

Commit 60b3112

Browse files
committed
feature: 쿠폰 확인 실패 시 재시도 메커니즘 추가
- 재시도 스케줄링을 처리하기 위해 `FailedEventStore` 도입. - `CouponUsageEventListener`에 예외 처리 로직을 추가하여 락 충돌 및 기타 오류 발생 시 재시도 수행. - 쿠폰 사용 확인 프로세스의 안정성을 강화.
1 parent 70fa290 commit 60b3112

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/coupon/CouponUsageEventListener.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.loopers.application.coupon;
22

3+
import com.loopers.application.event.FailedEventStore;
34
import com.loopers.application.payment.PaymentEvent.PaymentCompletedEvent;
45
import com.loopers.domain.coupon.CouponService;
56
import lombok.RequiredArgsConstructor;
7+
import org.springframework.orm.ObjectOptimisticLockingFailureException;
68
import org.springframework.stereotype.Component;
79
import org.springframework.transaction.annotation.Transactional;
810
import org.springframework.transaction.event.TransactionPhase;
@@ -12,13 +14,22 @@
1214
@RequiredArgsConstructor
1315
public class CouponUsageEventListener {
1416
private final CouponService couponService;
17+
private final FailedEventStore failedEventStore;
1518

1619
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
1720
@Transactional
1821
public void handlePaymentCompletedEvent(PaymentCompletedEvent event) {
1922

20-
if (event.couponId() != null) {
23+
if (event.couponId() == null) return;
24+
25+
try {
2126
couponService.confirmCouponUsage(event.couponId());
27+
28+
} catch (ObjectOptimisticLockingFailureException e) {
29+
failedEventStore.scheduleRetry(event, "Coupon Lock Conflict on Confirmation");
30+
31+
} catch (Exception e) {
32+
failedEventStore.scheduleRetry(event, "Coupon confirmation error: " + e.getMessage());
2233
}
2334
}
2435
}

apps/commerce-api/src/main/java/com/loopers/application/payment/PaymentEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.loopers.application.payment;
22

3+
import com.loopers.domain.event.DomainEvent;
4+
35
public class PaymentEvent {
46
public record PaymentRequestedEvent(
57
Long orderId,
@@ -12,7 +14,7 @@ public record PaymentCompletedEvent(
1214
Long paymentId,
1315
boolean isSuccess,
1416
Long couponId
15-
) {}
17+
) implements DomainEvent {}
1618

1719
public record PaymentRequestFailedEvent(
1820
Long orderId,

0 commit comments

Comments
 (0)