Skip to content

Commit

Permalink
Resolve #13; Deploy 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
binchoo committed Jul 2, 2022
1 parent b6baa42 commit d4b9fe8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ private List<UserRedeem> sendRequest(Collection<RedeemTask> redeemTasks, RedeemR
return wait(userRedeemList);
}

private List<UserRedeem> wait(List<Mono<UserRedeem>> userRedeemMonos) {
List<UserRedeem> userRedeems = new ArrayList<>();
wait(userRedeemMonos, userRedeems);
log.debug("{} user redemption has occurred: {}", userRedeems.size(), userRedeems);
return userRedeems;
}

private void wait(List<Mono<UserRedeem>> userRedeemMonos, List<UserRedeem> resultContainer) {
for (Mono<UserRedeem> userRedeemMono : userRedeemMonos) {
UserRedeem userRedeemObj = userRedeemMono.block();
if (resultContainer != null)
resultContainer.add(userRedeemObj);
}
}

/**
* 리뎀션 API를 호출하여 유저 리뎀션 수행 이력을 Mono 타입 리스트로 얻습니다.
* @param redeemTask 리딤 태스크 명세
Expand All @@ -75,22 +90,8 @@ private Mono<UserRedeem> sendRequest(RedeemTask redeemTask) {

private Mono<UserRedeem> wrap(Mono<HoyoResponse<CodeRedemptionResult>> 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<UserRedeem> wait(List<Mono<UserRedeem>> userRedeemMonos) {
List<UserRedeem> userRedeems = new ArrayList<>();
wait(userRedeemMonos, userRedeems);
log.debug("{} user redemption has occurred: {}", userRedeems.size(), userRedeems);
return userRedeems;
}

private void wait(List<Mono<UserRedeem>> userRedeemMonos, List<UserRedeem> resultContainer) {
for (Mono<UserRedeem> userRedeemMono : userRedeemMonos) {
UserRedeem userRedeemObj = userRedeemMono.block();
if (resultContainer != null)
resultContainer.add(userRedeemObj);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ protected List<List<SendMessageBatchRequestEntry>> taskSplit(List<RedeemTask> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
* @author : jbinchoo
* @since : 2022/04/17
*/
@Slf4j
@EqualsAndHashCode
@ToString
@Getter
@Data
@AllArgsConstructor
@RequiredArgsConstructor
public class UserRedeem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
Expand All @@ -35,6 +36,6 @@ public List<RedeemTask> generateTasks(RedeemTaskEstimationOption estimationOptio

private boolean hasNotRedeemed(RedeemTask redeemTask) {
return redeemHistoryPort.hasNotRedeemed(redeemTask.getBotUserId(),
redeemTask.getUidString(), redeemTask.getRedeemCode());
UUID.randomUUID().toString(), redeemTask.getRedeemCode());
}
}

0 comments on commit d4b9fe8

Please sign in to comment.