Skip to content

Commit

Permalink
Merge pull request #297 from Team-BC-1/refactor/add-retry-on-pessimis…
Browse files Browse the repository at this point in the history
…tic-lock

비관적 락 사용한 조회 호출에 대한 재시도 처리 적용
  • Loading branch information
vanillacake369 authored Mar 19, 2024
2 parents 3522c4e + 82327ff commit 09d3027
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -57,6 +59,7 @@ public Page<BuyPriceToQuantityResponseDto> findAllBuyBidsOf(Product product, Pag
* @param price 구매를 원하는 상품 가격
* @return 구매입찰
*/
@Retryable(backoff = @Backoff(delay = 100))
public Buy getRecentBuyBidOf(Long productId, Long price) {
return buyRepository.findByProductIdAndPrice(productId, price, LocalDateTime.now())
.orElseThrow(() -> new GlobalException(BUY_BID_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
import bc1.gream.domain.sell.repository.SellRepository;
import bc1.gream.domain.user.entity.User;
import bc1.gream.global.exception.GlobalException;
import java.time.LocalDateTime;
import bc1.gream.global.redis.RedisCacheName;
import bc1.gream.global.redis.RestPage;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -50,6 +52,7 @@ public Sell findByIdAndUser(Long sellId, User user) {
}

@Transactional(readOnly = true)
@Retryable(backoff = @Backoff(delay = 100))
public Sell getRecentSellBidof(Long productId, Long price) {
return sellRepository.findByProductIdAndPrice(productId, price, LocalDateTime.now()).orElseThrow(
() -> new GlobalException(SELL_BID_PRODUCT_NOT_FOUND)
Expand Down

0 comments on commit 09d3027

Please sign in to comment.