Repository navigation
#46 공동구매 정산 트리거 (스케줄러, 정원 참 즉시 정산) #48
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: feature/45
Are you sure you want to change the base?
Changes from all commits
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,11 @@ | ||
| package com.ttuk.global.config; | ||
|
|
||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
|
||
| @Configuration | ||
| @EnableScheduling | ||
| @ConditionalOnBooleanProperty(name = "ttuk.scheduling.enabled", matchIfMissing = true) | ||
| public class SchedulingConfig { | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.ttuk.grouppurchase; | ||
|
|
||
| import org.springframework.data.domain.Limit; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
@@ -8,6 +9,7 @@ | |
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public interface GroupPurchaseRepository extends JpaRepository<GroupPurchase, Long> { | ||
|
|
||
|
|
@@ -29,4 +31,13 @@ int closeOpen(@Param("groupPurchaseId") Long groupPurchaseId, | |
| @Param("now") LocalDateTime now); | ||
|
|
||
|
|
||
| @Query(""" | ||
| select g.id | ||
| from GroupPurchase g | ||
| where g.status = com.ttuk.grouppurchase.GroupPurchaseStatus.OPEN | ||
| and g.closeAt <= :threshold | ||
| order by g.closeAt | ||
| """) | ||
| List<Long> findSettlementTargetIds(@Param("threshold") LocalDateTime threshold, Limit limit); | ||
|
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. 인덱스가 있을 때 이 order by 는 따로 정렬 작업이 필요한가요? 인덱스가 (close_at, status) 순서였다면요?
Collaborator
Author
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. (status, close_at) 인덱스가 있으면 따로 정렬 작업이 필요 없습니다. status = 'OPEN'으로 OPEN 구간 시작점에 바로 가고, 그 안이 이미 close_at 순으로 정렬돼 있어 앞에서부터 읽다가 threshold를 넘거나 LIMIT만큼 찼을 때 멈춥니다. InnoDB 보조 인덱스에 PK가 붙어 있어 id만 읽는 이 쿼리는 테이블을 다시 읽지 않고 인덱스만으로 끝납니다. (close_at, status) 순서였다면 close_at 순으로 줄 서 있어 정렬은 여전히 필요 없지만, 첫 컬럼이 범위 조건이라 status로 구간을 좁히지 못하고 close_at <= threshold인 행을 전부 훑으며 OPEN만 골라내야 합니다. 마감 시각이 지난 공동구매는 대부분 이미 CLOSED나 CANCELED라서, 서비스가 오래될수록 스케줄러가 매번 건너뛰어야 할 과거 행이 계속 늘어납니다. 그래서 = 조건인 status를 앞에, 범위이자 정렬 기준인 close_at을 뒤에 두었습니다. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.ttuk.grouppurchase; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.domain.Limit; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.Clock; | ||
| import java.time.Duration; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class GroupPurchaseSettlementScheduler { | ||
|
|
||
| private static final Duration SETTLE_AFTER_CLOSE = Duration.ofMinutes(1); | ||
| private static final int BATCH_SIZE = 100; | ||
|
|
||
| private final GroupPurchaseRepository groupPurchaseRepository; | ||
| private final GroupPurchaseSettlementService settlementService; | ||
| private final Clock clock; | ||
|
|
||
| @Scheduled(fixedDelay = 30, timeUnit = TimeUnit.SECONDS) | ||
|
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. fixedRate 대신 fixedDelay 를 고른 이유는 뭔가요? 한 바퀴가 40초 걸리면 각각 어떻게 동작하나요?
Collaborator
Author
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. fixedDelay는 이전 실행이 끝난 시각부터, fixedRate는 이전 실행이 시작한 시각부터 간격을 셉니다. 한 바퀴가 40초 걸리면 fixedDelay는 40초에 끝나고 30초 쉰 뒤 70초에 다시 시작해 실행 사이에 항상 30초 쉬는 시간이 생깁니다. fixedRate는 30초에 다음 차례가 왔지만 아직 실행 중이라 기다렸다가 40초에 끝나자마자 바로 시작하고, 그다음도 80초에 바로 이어서 시작하는 식으로 쉬지 않고 연달아 실행됩니다. 기본 스케줄러에서 같은 작업이 동시에 두 번 돌지는 않지만, 실행이 주기보다 길어지는 동안은 계속 붙어서 돕니다. 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. 나중에 다른 @scheduled 작업이 추가되고, 이 정산이 오래 걸리면 그 작업은 어떻게 되나요?
Collaborator
Author
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. 확인해 보니 Spring Boot가 자동 구성하는 스케줄러는 스레드가 기본 1개라서, 다른 @scheduled 작업이 추가되면 정산이 끝날 때까지 실행 시각이 와도 기다리게 됩니다. 에러 없이 조용히 밀리기 때문에 알아차리기도 어렵습니다. 정산은 한 번에 최대 100건을 순서대로 처리하고 건마다 Redis 읽기와 DB 트랜잭션이 있어서, Redis나 DB가 느려지면 한 바퀴가 길어지고 그만큼 다른 작업이 묶입니다. 정산 자신은 fixedDelay라 끝난 뒤 30초 후에 다시 돌기 때문에 스스로 겹치지는 않습니다. |
||
| public void settleClosedGroupPurchases(){ | ||
|
|
||
| LocalDateTime threshold = LocalDateTime.now(clock).minus(SETTLE_AFTER_CLOSE); | ||
| List<Long> ids = groupPurchaseRepository.findSettlementTargetIds(threshold, Limit.of(BATCH_SIZE)); | ||
|
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. 서버가 2대면 같은 공동구매를 두 서버가 동시에 뽑아요. 분산 락(ShedLock 같은) 없이도 괜찮은 이유와, 그래도 락을 쓰는 경우는 언제인가요?
Collaborator
Author
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. 서버가 2대면 각 서버의 스케줄러가 따로 돌기 때문에, 거의 같은 시각에 정산 대상을 조회하면 두 서버 모두 같은 공동구매 id를 받아 같은 공동구매에 settle을 호출할 수 있습니다. 하지만 정산은 한 번만 성공하도록 DB에서 막고 있어서 분산 락 없이 진행했습니다. |
||
| for(Long id: ids){ | ||
| try { | ||
| settlementService.settle(id); | ||
| } catch (RuntimeException e) { | ||
| log.error("정산 실패. groupPurchaseId={}", id, e); | ||
|
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. 정산이 계속 실패하는 건은 OPEN 으로 남아서 매 바퀴 마감 순서 맨 앞에 다시 뽑혀요. 이런 건이 100개 쌓이면 뒤의 정상 건은 영영 정산되지 않아요. 실패 횟수를 기록해서 빼거나, 실패한 건을 따로 표시하는 방법이 필요해 보여요.
Collaborator
Author
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. 확인해 보니 말씀해 주신 대로 정산에서 예외가 나면 closeOpen이 커밋되지 않아 OPEN으로 남고, close_at 순서상 매 바퀴 맨 앞에 다시 뽑혀 이런 건이 100개 쌓이면 LIMIT 100을 모두 차지해 뒤의 정상 건이 정산되지 않습니다. 예를 들어 meta는 남아 있는데 인원·단가 키가 없으면 SettlementSnapshot.from이 매번 예외를 던지기 때문에, 이런 건은 재시도로 해결되지 않습니다. |
||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import com.ttuk.global.error.ErrorCode; | ||
| import com.ttuk.grouppurchase.GroupPurchase; | ||
| import com.ttuk.grouppurchase.GroupPurchaseRepository; | ||
| import com.ttuk.grouppurchase.GroupPurchaseSettlementService; | ||
| import com.ttuk.grouppurchase.GroupPurchaseStatus; | ||
| import com.ttuk.grouppurchase.redis.CancelResult; | ||
| import com.ttuk.grouppurchase.redis.GroupPurchaseRedisRepository; | ||
|
|
@@ -29,6 +30,7 @@ public class ParticipationService { | |
| private final MemberRepository memberRepository; | ||
| private final ParticipationRepository participationRepository; | ||
| private final Clock clock; | ||
| private final GroupPurchaseSettlementService settlementService; | ||
|
|
||
| public ParticipationCreateResponse join(Long groupPurchaseId, Long memberId, int quantity) { | ||
| JoinResult result = groupPurchaseRedisRepository.join(groupPurchaseId, memberId); | ||
|
|
@@ -37,7 +39,14 @@ public ParticipationCreateResponse join(Long groupPurchaseId, Long memberId, int | |
| } | ||
|
|
||
| return switch (result.outcome()) { | ||
| case JOINED -> saveParticipation(groupPurchaseId, memberId, quantity, result); | ||
| case JOINED ->{ | ||
| ParticipationCreateResponse response = saveParticipation(groupPurchaseId, memberId, quantity, result); | ||
| if(result.closed()){ | ||
| settleFilledGroupPurchase(groupPurchaseId); | ||
|
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. 스케줄러는 마감 1분 뒤에 정산해서, 진행 중인 DB 저장과 보상이 끝나길 기다려요. 그런데 정원이 찼을 때는 바로 정산해서 이 여유가 없어요. 49번째 참여자의 DB 저장이 아직 진행 중일 때 50번째가 정산하면 49번째를 인원에 넣고 마감해요. 그 뒤 49번째 저장이 실패하면 rollbackJoin 이 Redis 를 다시 OPEN 으로 바꿔요. 그러면 DB 는 CLOSED 인데 새 참여를 받아요. 정원 정산도 잠깐 기다리게 하거나, 정산 후에는 rollbackJoin 이 다시 열지 않게 해야 할 것 같아요.
Collaborator
Author
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. 확인해 보니 말씀해 주신 대로 정원 즉시 정산은 마지막 참여자 본인의 DB 저장만 기다리고 다른 참여자의 진행 중인 저장은 기다리지 않습니다. 정원이 차면 참여 Lua가 Redis status를 CLOSED로 바꾸는데 정산은 DB만 CLOSED로 바꾸고 Redis는 건드리지 않아서, Redis에서는 정원이 찬 상태와 정산이 끝난 상태를 구분할 수 없습니다. 그래서 정산 후 49번째 저장이 실패하면 rollbackJoin이 CLOSED이면서 정원 미만인 것을 보고 OPEN으로 되돌리고, DB는 CLOSED인데 Redis가 새 참여를 받게 됩니다. 마감 시각 정산은 status 키가 마감 시각에 만료돼 rollbackJoin이 다시 열지 않기 때문에, 정원 정산에서만 생기는 문제입니다. 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. 정산을 참여 요청 안에서 바로 호출하지 않고, 이벤트를 발행해서 따로 처리하면 무엇이 달라지나요?
Collaborator
Author
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. 이벤트로 분리하면 참여 서비스는 "정원이 찼다"는 사실만 발행하고 정산은 리스너가 맡아서, 정원이 찬 뒤 마감 알림 같은 후속 처리를 붙여도 참여 코드를 바꾸지 않아도 됩니다. 리스너를 비동기로 실행하면 마지막 참여자도 정산을 기다리지 않고 바로 응답을 받습니다. 대신 흐름이 참여 코드에 드러나지 않고, 비동기 이벤트는 메모리에만 있어 발행 직후 앱이 꺼지면 사라질 수 있습니다. |
||
| } | ||
| yield response; | ||
| } | ||
|
|
||
| case NOT_OPEN -> throw new BusinessException(ErrorCode.GROUP_PURCHASE_NOT_OPEN); | ||
| case FULL -> throw new BusinessException(ErrorCode.GROUP_PURCHASE_FULL); | ||
| case INVALID_HEADCOUNT -> throw new IllegalStateException("Redis 참여 인원 값이 올바르지 않습니다. groupPurchaseId=" + groupPurchaseId); | ||
|
|
@@ -132,4 +141,12 @@ private void rollbackRedis(Long groupPurchaseId, Long memberId, RuntimeException | |
| groupPurchaseId, memberId, rollbackFailure); | ||
| } | ||
| } | ||
|
|
||
| private void settleFilledGroupPurchase(Long groupPurchaseId) { | ||
| try { | ||
| settlementService.settle(groupPurchaseId); | ||
| } catch (RuntimeException e) { | ||
| log.error("정원 참 정산 실패: 마감 시각 이후 스케줄러가 다시 정산함. groupPurchaseId={}", groupPurchaseId, e); | ||
|
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. 정원 정산이 실패하면 스케줄러는 마감 시각 이후에야 다시 정산해요. 마감이 3일 뒤면 그동안 DB 는 OPEN 으로 남아요. 괜찮은 건지 확인 부탁드려요.
Collaborator
Author
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. 확인해 보니 말씀해 주신 대로 스케줄러는 close_at 기준으로만 대상을 뽑기 때문에, 정원 정산이 실패하면 마감까지 다시 정산할 경로가 없습니다. 정원이 차면 참여 Lua가 Redis status를 CLOSED로 바꾸기 때문에 새 참여와 참여 취소, 판매자 취소는 Redis Lua에서 거절되고 상세 조회도 Redis status를 우선해 CLOSED로 보입니다. 하지만 목록 조회와 개수는 DB status = OPEN 조건이라 마감까지 모집 중 목록에 계속 남고, 참여자도 확정 결과를 마감 시각 이후에야 받게 됩니다. |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| package com.ttuk.grouppurchase; | ||
|
|
||
| import com.ttuk.category.Category; | ||
| import com.ttuk.category.CategoryRepository; | ||
| import com.ttuk.grouppurchase.redis.GroupPurchaseRedisKeys; | ||
| import com.ttuk.grouppurchase.redis.GroupPurchaseRedisRepository; | ||
| import com.ttuk.member.Member; | ||
| import com.ttuk.member.MemberRepository; | ||
| import com.ttuk.member.MemberRole; | ||
| import com.ttuk.participation.ParticipationRepository; | ||
| import com.ttuk.participation.ParticipationService; | ||
| import com.ttuk.support.TestcontainersConfig; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.data.redis.core.StringRedisTemplate; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| import java.time.Clock; | ||
| import java.time.LocalDateTime; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @SpringBootTest | ||
| @Import(TestcontainersConfig.class) | ||
| class GroupPurchaseSettlementTriggerIntegrationTest { | ||
|
|
||
| private static final long FRESH_FOOD_ID = 1L; | ||
|
|
||
| @Autowired | ||
| GroupPurchaseSettlementScheduler settlementScheduler; | ||
| @Autowired | ||
| ParticipationService participationService; | ||
| @Autowired | ||
| MemberRepository memberRepository; | ||
| @Autowired | ||
| CategoryRepository categoryRepository; | ||
| @Autowired | ||
| GroupPurchaseRepository groupPurchaseRepository; | ||
| @Autowired | ||
| ParticipationRepository participationRepository; | ||
| @Autowired | ||
| GroupPurchaseRedisRepository groupPurchaseRedisRepository; | ||
| @Autowired | ||
| StringRedisTemplate redisTemplate; | ||
| @Autowired | ||
| JdbcTemplate jdbcTemplate; | ||
| @Autowired | ||
| Clock clock; | ||
|
|
||
| private Member seller; | ||
| private Member buyer1; | ||
| private Member buyer2; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| seller = memberRepository.save(member("seller@ttuk.kr", "진도농장", MemberRole.SELLER, "01011112222")); | ||
| buyer1 = memberRepository.save(member("buyer1@ttuk.kr", "구매자1", MemberRole.BUYER, "01033334444")); | ||
| buyer2 = memberRepository.save(member("buyer2@ttuk.kr", "구매자2", MemberRole.BUYER, "01055556666")); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void cleanUp() { | ||
| Set<String> keys = redisTemplate.keys("group_purchase:*"); | ||
| redisTemplate.delete(keys); | ||
| participationRepository.deleteAll(); | ||
| groupPurchaseRepository.deleteAll(); | ||
| memberRepository.deleteAll(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("스케줄러는 마감 후 1분이 지난 OPEN 공동구매만 정산한다") | ||
| void scheduler_settlesOnlyClosedOverOneMinute() { | ||
|
Check warning on line 79 in src/test/java/com/ttuk/grouppurchase/GroupPurchaseSettlementTriggerIntegrationTest.java
|
||
| LocalDateTime now = LocalDateTime.now(clock).withNano(0); | ||
| GroupPurchase closedLongAgo = saveGroupPurchase(now.minusMinutes(2), 50); | ||
| GroupPurchase closedJustNow = saveGroupPurchase(now.minusSeconds(30), 50); | ||
| GroupPurchase stillOpen = saveGroupPurchase(now.plusDays(3), 50); | ||
|
|
||
| settlementScheduler.settleClosedGroupPurchases(); | ||
|
|
||
| assertThat(statusOf(closedLongAgo.getId())).isEqualTo("CLOSED"); | ||
| assertThat(statusOf(closedJustNow.getId())).isEqualTo("OPEN"); | ||
| assertThat(statusOf(stillOpen.getId())).isEqualTo("OPEN"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("스케줄러는 한 공동구매의 정산이 실패해도 다음 공동구매를 정산한다") | ||
| void scheduler_continuesAfterFailure() { | ||
|
Check warning on line 94 in src/test/java/com/ttuk/grouppurchase/GroupPurchaseSettlementTriggerIntegrationTest.java
|
||
| LocalDateTime now = LocalDateTime.now(clock).withNano(0); | ||
| GroupPurchase broken = saveGroupPurchase(now.plusDays(3), 50); | ||
| groupPurchaseRedisRepository.initialize(broken); | ||
| jdbcTemplate.update("UPDATE group_purchase SET close_at = ? WHERE id = ?", | ||
| now.minusHours(2), broken.getId()); | ||
| redisTemplate.delete(GroupPurchaseRedisKeys.status(broken.getId())); | ||
| redisTemplate.delete(GroupPurchaseRedisKeys.headcount(broken.getId())); | ||
| GroupPurchase normal = saveGroupPurchase(now.minusHours(1), 50); | ||
|
|
||
| settlementScheduler.settleClosedGroupPurchases(); | ||
|
|
||
| assertThat(statusOf(broken.getId())).isEqualTo("OPEN"); | ||
| assertThat(statusOf(normal.getId())).isEqualTo("CLOSED"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("정원을 채운 참여 직후 바로 정산하고, 그 전 참여에서는 정산하지 않는다") | ||
| void join_settlesWhenFilled() { | ||
|
Check warning on line 112 in src/test/java/com/ttuk/grouppurchase/GroupPurchaseSettlementTriggerIntegrationTest.java
|
||
| GroupPurchase groupPurchase = saveGroupPurchase(LocalDateTime.now(clock).plusDays(3).withNano(0), 2); | ||
| groupPurchaseRedisRepository.initialize(groupPurchase); | ||
| Long id = groupPurchase.getId(); | ||
|
|
||
| participationService.join(id, buyer1.getId(), 1); | ||
| assertThat(statusOf(id)).isEqualTo("OPEN"); | ||
|
|
||
| participationService.join(id, buyer2.getId(), 1); | ||
| Map<String, Object> row = groupPurchaseRow(id); | ||
| assertThat(row.get("status")).isEqualTo("CLOSED"); | ||
| assertThat(row.get("final_headcount")).isEqualTo(2); | ||
| assertThat(row.get("final_price")).isEqualTo(2850); | ||
| } | ||
|
|
||
| private String statusOf(Long groupPurchaseId) { | ||
| return jdbcTemplate.queryForObject( | ||
| "SELECT status FROM group_purchase WHERE id = ?", String.class, groupPurchaseId); | ||
| } | ||
|
|
||
| private Map<String, Object> groupPurchaseRow(Long groupPurchaseId) { | ||
| return jdbcTemplate.queryForMap( | ||
| "SELECT status, final_headcount, final_price FROM group_purchase WHERE id = ?", | ||
| groupPurchaseId); | ||
| } | ||
|
|
||
| private GroupPurchase saveGroupPurchase(LocalDateTime closeAt, int maxHeadcount) { | ||
| Category category = categoryRepository.findById(FRESH_FOOD_ID).orElseThrow(); | ||
| return groupPurchaseRepository.save(GroupPurchase.builder() | ||
| .seller(seller) | ||
| .category(category) | ||
| .title("대파 한 단") | ||
| .description("진도 대파, 11/12 수확") | ||
| .unit("단") | ||
| .basePrice(3000) | ||
| .floorPrice(2500) | ||
| .discountType(DiscountType.RATE) | ||
| .discountValue(5) | ||
| .discountStepSize(2) | ||
| .maxHeadcount(maxHeadcount) | ||
| .closeAt(closeAt) | ||
| .build()); | ||
| } | ||
|
|
||
| private Member member(String email, String nickname, MemberRole role, String phoneNum) { | ||
| return Member.builder() | ||
| .email(email) | ||
| .encodedPassword("{noop}a123456789") | ||
| .nickname(nickname) | ||
| .role(role) | ||
| .phoneNum(phoneNum) | ||
| .zipCode("06236") | ||
| .address("서울시 강남구 테헤란로 123") | ||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ttuk: | ||
| scheduling: | ||
| enabled: false |
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.
matchIfMissing = true 는 어떤 뜻인가요? false 였다면 운영 서버에서 무엇을 빠뜨리기 쉬울까요?
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.
matchIfMissing = true는 ttuk.scheduling.enabled 설정이 아예 없을 때도 조건을 만족한 것으로 보고 스케줄링을 켠다는 뜻입니다. 그래서 기본은 켜져 있고, 스케줄러가 테스트 데이터를 중간에 정산하지 않도록 테스트 설정에서만 false로 명시해 끄고 있습니다.
false였다면 운영 서버 설정에 enabled: true를 빠뜨리는 순간 스케줄링이 꺼져, 정원을 채우지 못한 공동구매는 마감 시각이 지나도 정산되지 않습니다. 스케줄러가 실패하는 게 아니라 아예 실행되지 않아 에러 로그도 남지 않아서 늦게 발견되기 쉽습니다. 지금처럼 두면 운영에서 설정을 빠뜨려도 정산은 정상적으로 돌고, 테스트에서 끄는 걸 빠뜨리면 테스트가 흔들려 바로 드러나기 때문에, 꼭 돌아야 하는 기능은 기본값을 켜짐으로 두었습니다.