-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(#235): 경매 활성화/만료/카드동기화 배치를 메인앱 Internal API 위임으로 전환 #12
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c3fd31b
refactor(#235): 경매 활성화/만료/카드동기화 배치를 메인앱 internal API 위임으로 전환
cdkkyj123 e6fa94b
docs(#235): RUNBOOK/ARCHITECTURE 업데이트 (Internal API 위임 전환)
cdkkyj123 2997994
chore(#235): 외부 리뷰 재요청을 위한 빈 커밋
cdkkyj123 0412253
fix(#235): 외부 리뷰 반영 — MD040, 4xx fail-fast, failedCount>0 step 실패 처리
cdkkyj123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/com/rocketcrew/pocatbatch/client/MainAuctionLifecycleClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package com.rocketcrew.pocatbatch.client; | ||
|
|
||
| import com.rocketcrew.pocatbatch.client.dto.ApiResponseEnvelope; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.core.ParameterizedTypeReference; | ||
| import org.springframework.http.HttpEntity; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class MainAuctionLifecycleClient { | ||
|
|
||
| private final RestTemplate restTemplate; | ||
|
|
||
| @Value("${pocat.main-app.base-url}") | ||
| private String baseUrl; | ||
|
|
||
| @Value("${pocat.main-app.internal-token}") | ||
| private String internalToken; | ||
|
|
||
| /** | ||
| * 경매 활성화 요청 | ||
| * POST {baseUrl}/internal/auctions/{auctionId}/activate | ||
| * 최대 3회 재시도 (지수 백오프) | ||
| * 4xx 오류는 즉시 RuntimeException 발생 | ||
| */ | ||
| public boolean activate(Long auctionId, long jobExecutionId) { | ||
| String url = String.format("%s/internal/auctions/%d/activate", baseUrl, auctionId); | ||
| String idempotencyKey = String.format("auction-activate-%d-%d", auctionId, jobExecutionId); | ||
| return call(url, idempotencyKey, auctionId); | ||
| } | ||
|
|
||
| /** | ||
| * 경매 만료 종료 요청 | ||
| * POST {baseUrl}/internal/auctions/{auctionId}/close-expired | ||
| * 최대 3회 재시도 (지수 백오프) | ||
| * 4xx 오류는 즉시 RuntimeException 발생 | ||
| */ | ||
| public boolean closeExpired(Long auctionId, long jobExecutionId) { | ||
| String url = String.format("%s/internal/auctions/%d/close-expired", baseUrl, auctionId); | ||
| String idempotencyKey = String.format("auction-close-%d-%d", auctionId, jobExecutionId); | ||
| return call(url, idempotencyKey, auctionId); | ||
| } | ||
|
|
||
| private boolean call(String url, String idempotencyKey, Long auctionId) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.set("X-Internal-Token", internalToken); | ||
| headers.set("Idempotency-Key", idempotencyKey); | ||
|
|
||
| HttpEntity<Void> request = new HttpEntity<>(headers); | ||
|
|
||
| int maxRetries = 3; | ||
| long delayMs = 1000; | ||
|
|
||
| for (int attempt = 1; attempt <= maxRetries; attempt++) { | ||
| try { | ||
| ResponseEntity<ApiResponseEnvelope<Boolean>> responseEntity = restTemplate.exchange( | ||
| url, HttpMethod.POST, request, | ||
| new ParameterizedTypeReference<ApiResponseEnvelope<Boolean>>() {}); | ||
| ApiResponseEnvelope<Boolean> body = responseEntity.getBody(); | ||
| if (body == null) { | ||
| throw new IllegalStateException("경매 라이프사이클 응답 본문이 null입니다: auctionId=" + auctionId); | ||
| } | ||
| if (!body.success()) { | ||
| throw new IllegalStateException("경매 라이프사이클 요청이 실패했습니다: status=" + body.status() + ", auctionId=" + auctionId); | ||
| } | ||
| if (body.data() == null) { | ||
| throw new IllegalStateException("경매 라이프사이클 응답 데이터가 null입니다: auctionId=" + auctionId); | ||
| } | ||
| return body.data(); | ||
| } catch (HttpClientErrorException e) { | ||
| log.warn("경매 라이프사이클 4xx 오류: auctionId={}, status={}", auctionId, e.getStatusCode()); | ||
| throw new RuntimeException("4xx 오류로 스킵", e); | ||
| } catch (Exception e) { | ||
| if (attempt == maxRetries) { | ||
| log.error("경매 라이프사이클 요청 실패: auctionId={}", auctionId, e); | ||
| throw e instanceof RuntimeException re ? re : new RuntimeException(e); | ||
| } | ||
| try { | ||
| Thread.sleep(delayMs); | ||
| delayMs *= 2; | ||
| } catch (InterruptedException ie) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException(ie); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new IllegalStateException("재시도 루프를 빠져나올 수 없습니다"); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/rocketcrew/pocatbatch/client/MainCardSyncClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.rocketcrew.pocatbatch.client; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpEntity; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class MainCardSyncClient { | ||
|
|
||
| private final RestTemplate restTemplate; | ||
|
|
||
| @Value("${pocat.main-app.base-url}") | ||
| private String baseUrl; | ||
|
|
||
| @Value("${pocat.main-app.internal-token}") | ||
| private String internalToken; | ||
|
|
||
| /** | ||
| * 카드 동기화 트리거 요청 | ||
| * POST {baseUrl}/internal/cards/sync | ||
| * 202 -> 정상 처리 | ||
| * 409 (CARD_SYNC_IN_PROGRESS) -> 로그 후 정상 스킵 | ||
| * 401 -> RuntimeException | ||
| * 그 외 4xx -> 로그 후 정상 스킵 | ||
| */ | ||
| public void triggerSync(long jobExecutionId) { | ||
| String url = String.format("%s/internal/cards/sync", baseUrl); | ||
|
|
||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.set("X-Internal-Token", internalToken); | ||
|
|
||
| HttpEntity<Void> request = new HttpEntity<>(headers); | ||
|
|
||
| try { | ||
| restTemplate.exchange(url, HttpMethod.POST, request, Void.class); | ||
| log.info("카드 동기화 트리거 요청 성공: jobExecutionId={}", jobExecutionId); | ||
| } catch (HttpClientErrorException e) { | ||
| if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { | ||
| log.error("카드 동기화 트리거 401 오류: jobExecutionId={}", jobExecutionId); | ||
| throw new RuntimeException("카드 동기화 트리거 인증 실패", e); | ||
| } | ||
|
|
||
| String responseBody = e.getResponseBodyAsString(); | ||
| if (e.getStatusCode() == HttpStatus.CONFLICT && responseBody.contains("CARD_SYNC_IN_PROGRESS")) { | ||
| log.info("카드 동기화가 이미 진행 중이어서 스킵합니다: jobExecutionId={}", jobExecutionId); | ||
| return; | ||
| } | ||
|
|
||
| log.warn("카드 동기화 트리거 4xx 오류로 스킵: jobExecutionId={}, status={}, body={}", | ||
| jobExecutionId, e.getStatusCode(), responseBody); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.