diff --git a/Makefile b/Makefile index 3d957dbb..abe7bd44 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,14 @@ paimonganyu-skill-prod: build paimonganyu-prod: build cd sam/paimonganyu; sam deploy --guided \ + --stack-name paimonganyu \ --profile serverless \ --region ap-northeast-2 \ --parameter-overrides Env=prod paimonganyu-test: build cd sam/paimonganyu; sam deploy --guided \ + --stack-name paimonganyu-test --profile serverless \ --region ap-northeast-1 \ --parameter-overrides Env=test diff --git a/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/infra/redeem/web/RedemptionClientAdapter.java b/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/infra/redeem/web/RedemptionClientAdapter.java index 68424326..f204dea4 100644 --- a/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/infra/redeem/web/RedemptionClientAdapter.java +++ b/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/infra/redeem/web/RedemptionClientAdapter.java @@ -54,6 +54,21 @@ private List sendRequest(Collection redeemTasks, RedeemR return wait(userRedeemList); } + private List wait(List> userRedeemMonos) { + List userRedeems = new ArrayList<>(); + wait(userRedeemMonos, userRedeems); + log.debug("{} user redemption has occurred: {}", userRedeems.size(), userRedeems); + return userRedeems; + } + + private void wait(List> userRedeemMonos, List resultContainer) { + for (Mono userRedeemMono : userRedeemMonos) { + UserRedeem userRedeemObj = userRedeemMono.block(); + if (resultContainer != null) + resultContainer.add(userRedeemObj); + } + } + /** * 리뎀션 API를 호출하여 유저 리뎀션 수행 이력을 Mono 타입 리스트로 얻습니다. * @param redeemTask 리딤 태스크 명세 @@ -75,22 +90,8 @@ private Mono sendRequest(RedeemTask redeemTask) { private Mono wrap(Mono> response, UserRedeem userRedeem) { // must apply asychronous mapping: flatMap! - return response.flatMap(hoyoResponse-> Mono.just(userRedeem.markDone())) + return response.log() + .flatMap(hoyoResponse-> Mono.just(userRedeem.markDone())) .onErrorReturn(userRedeem); } - - private List wait(List> userRedeemMonos) { - List userRedeems = new ArrayList<>(); - wait(userRedeemMonos, userRedeems); - log.debug("{} user redemption has occurred: {}", userRedeems.size(), userRedeems); - return userRedeems; - } - - private void wait(List> userRedeemMonos, List resultContainer) { - for (Mono userRedeemMono : userRedeemMonos) { - UserRedeem userRedeemObj = userRedeemMono.block(); - if (resultContainer != null) - resultContainer.add(userRedeemObj); - } - } } diff --git a/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambda.java b/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambda.java index da6e3eda..e376d43c 100644 --- a/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambda.java +++ b/PaimonGanyu/application/src/main/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambda.java @@ -69,8 +69,8 @@ protected List> taskSplit(List ta int fetch = Math.min(batchSize, taskQueue.size()); while (fetch-- > 0) { RedeemTask task = taskQueue.removeFirst(); - SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry( - task.getBotUserId(), task.getJson(objectMapper)); + String uniqueId = UUID.randomUUID().toString(); + SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry(uniqueId, task.getJson(objectMapper)); batch.add(entry); } batches.add(batch); diff --git a/PaimonGanyu/application/src/test/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambdaTest.java b/PaimonGanyu/application/src/test/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambdaTest.java index caeedcb1..2456e49b 100644 --- a/PaimonGanyu/application/src/test/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambdaTest.java +++ b/PaimonGanyu/application/src/test/java/org/binchoo/paimonganyu/lambda/redeem/RedeemCodeDeliveryLambdaTest.java @@ -23,11 +23,11 @@ void bootstrap() { @Test void taskSplit() { - int n = 100, batchSize = 10; + int n = 101, batchSize = 10; int expectedBatches = (n % batchSize == 0)? n / batchSize : (n / batchSize + 1); - var codeDelivery = new RedeemCodeDeliveryLambda(); var tasks = task(n); + var codeDelivery = new RedeemCodeDeliveryLambda(); var batch = codeDelivery.taskSplit(tasks, batchSize); assertThat(batch).hasSize(expectedBatches); diff --git a/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/redeem/UserRedeem.java b/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/redeem/UserRedeem.java index b07ac64d..1e05176f 100644 --- a/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/redeem/UserRedeem.java +++ b/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/redeem/UserRedeem.java @@ -8,10 +8,7 @@ * @author : jbinchoo * @since : 2022/04/17 */ -@Slf4j -@EqualsAndHashCode -@ToString -@Getter +@Data @AllArgsConstructor @RequiredArgsConstructor public class UserRedeem { diff --git a/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/service/redeem/RedeemTaskEstimator.java b/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/service/redeem/RedeemTaskEstimator.java index 1957c1d1..92823860 100644 --- a/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/service/redeem/RedeemTaskEstimator.java +++ b/PaimonGanyu/domain/src/main/java/org/binchoo/paimonganyu/service/redeem/RedeemTaskEstimator.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -35,6 +36,6 @@ public List generateTasks(RedeemTaskEstimationOption estimationOptio private boolean hasNotRedeemed(RedeemTask redeemTask) { return redeemHistoryPort.hasNotRedeemed(redeemTask.getBotUserId(), - redeemTask.getUidString(), redeemTask.getRedeemCode()); + UUID.randomUUID().toString(), redeemTask.getRedeemCode()); } }