-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 스마트 컨트랙트 환불 메소드 호출하는 서버 스케줄러 작성 #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3fbf175
12879c8
03ea920
34dd6b6
7f80a64
37f9d91
dbd8bf0
9964f7a
99e5458
5327622
3aa54f0
c91986b
6470df4
a4203be
17cce40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.donet.donet.donation.adapter.in.scheduler; | ||
|
|
||
| import com.donet.donet.donation.application.port.in.RefundDonationUsecase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class RefundScheduler { | ||
| private final RefundDonationUsecase refundDonationUsecase; | ||
|
|
||
| @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") | ||
| public void runRefundJob() { | ||
| refundDonationUsecase.refundDonation(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.donet.donet.donation.application; | ||
|
|
||
| import com.donet.donet.donation.application.port.in.RefundDonationUsecase; | ||
| import com.donet.donet.donation.application.port.out.FindDonationPort; | ||
| import com.donet.donet.donation.application.port.out.SmartContractPort; | ||
| import com.donet.donet.donation.domain.Donation; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class RefundDonationService implements RefundDonationUsecase { | ||
|
|
||
| private final FindDonationPort findDonationPort; | ||
| private final SmartContractPort smartContractPort; | ||
|
|
||
| @Override | ||
| public void refundDonation() { | ||
| List<Long> refundTargetDonationIds = findDonationPort.findRefundableDonation() | ||
| .stream() | ||
| .map(Donation::getId) | ||
| .toList(); | ||
|
|
||
| if (refundTargetDonationIds.isEmpty()) { | ||
| log.info("환불 대상 기부가 없습니다."); | ||
| return; | ||
| } | ||
|
|
||
| log.info("환불 처리 시작: {} 건", refundTargetDonationIds.size()); | ||
| boolean success = smartContractPort.refundDonations(refundTargetDonationIds); | ||
|
|
||
| if (success) { | ||
| log.info("환불 처리 완료: {} 건", refundTargetDonationIds.size()); | ||
| }else{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 포맷팅을 수정하세요.
다음과 같이 수정하세요: - }else{
+ } else {🤖 Prompt for AI Agents |
||
| log.error("환불 처리 실패: donation IDs = {}", refundTargetDonationIds); | ||
| } | ||
|
Comment on lines
+34
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 부분 실패 시나리오를 처리하세요.
다음을 고려하세요:
이 설계 변경이 필요하다면, SmartContractPort 인터페이스 수정 및 어댑터 구현 코드 생성을 도와드릴 수 있습니다. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.donet.donet.donation.application.port.in; | ||
|
|
||
| public interface RefundDonationUsecase { | ||
| void refundDonation(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.donet.donet.donation.application.port.out; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface SmartContractPort { | ||
| boolean refundDonations(List<Long> donationIds); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
예외 처리 전략을 검증하세요.
findDonationPort.findRefundableDonation()호출 시 발생할 수 있는 예외(DB 연결 실패, 타임아웃 등)가 처리되지 않고 있습니다. 스케줄러가 예외로 인해 중단될 수 있으며, 이후 실행에도 영향을 줄 수 있습니다.다음을 확인하세요:
다음 스크립트로 스케줄러의 예외 처리 구현을 확인하세요:
🏁 Script executed:
Length of output: 327
스케줄러 레벨의 예외 처리를 더 자세히 검증하기 위해 RefundDonationService 구현을 확인하겠습니다.
Length of output: 1390
🏁 Script executed:
Length of output: 124
🏁 Script executed:
Length of output: 2399
🏁 Script executed:
Length of output: 0
추가로 프로젝트 레벨의 글로벌 에러 핸들링 설정을 확인하겠습니다.
Length of output: 0
🏁 Script executed:
Length of output: 3726
🏁 Script executed:
Length of output: 6038
findDonationPort.findRefundableDonation()호출에 예외 처리 추가 필요합니다.검증 결과, RefundDonationService의 23-26번 줄에서 데이터베이스 조회 메소드를 호출할 때 예외 처리가 없습니다. DB 연결 실패, 타임아웃 등의 예외가 발생하면 스케줄러로 전파되어 실행 흐름이 중단됩니다. Spring @scheduled는 예외를 로깅하고 다음 스케줄에 계속 실행되지만, 애플리케이션 레벨의 명시적인 예외 처리 전략이 부재합니다.
다음과 같이 예외 처리를 추가하세요:
findRefundableDonation()호출 감싸기refundDonation()메소드에 예외 처리 추가🤖 Prompt for AI Agents