Skip to content

Commit

Permalink
fix: currentPrice 조회에 에러 폴백 연산 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghwankim-dev committed Aug 25, 2024
1 parent a9205da commit d9bf3d3
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
import codesquad.fineants.domain.kis.client.KisClient;
import codesquad.fineants.domain.kis.client.KisCurrentPrice;
import codesquad.fineants.global.common.delay.DelayManager;
import codesquad.fineants.global.errors.exception.kis.CredentialsTypeKisException;
import codesquad.fineants.global.errors.exception.kis.ExpiredAccessTokenKisException;
import codesquad.fineants.global.errors.exception.kis.RequestLimitExceededKisException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

@RequiredArgsConstructor
@Repository
@Slf4j
public class CurrentPriceRedisRepository implements PriceRepository {
private static final String CURRENT_PRICE_FORMAT = "cp:%s";
private final RedisTemplate<String, String> redisTemplate;
Expand Down Expand Up @@ -49,7 +56,12 @@ private Optional<String> getCachedPrice(String tickerSymbol) {

private Optional<KisCurrentPrice> fetchAndCachePriceFromKis(String tickerSymbol) {
return kisClient.fetchCurrentPrice(tickerSymbol)
.retryWhen(Retry.fixedDelay(5, delayManager.fixedDelay()))
.doOnSuccess(kisCurrentPrice -> log.debug("reload stock current price {}", kisCurrentPrice))
.onErrorResume(ExpiredAccessTokenKisException.class::isInstance, throwable -> Mono.empty())
.onErrorResume(CredentialsTypeKisException.class::isInstance, throwable -> Mono.empty())
.retryWhen(Retry.fixedDelay(5, delayManager.fixedDelay())
.filter(RequestLimitExceededKisException.class::isInstance))
.onErrorResume(Exceptions::isRetryExhausted, throwable -> Mono.empty())
.blockOptional(delayManager.timeout())
.map(this::savePrice);
}
Expand Down

0 comments on commit d9bf3d3

Please sign in to comment.