Skip to content

Commit 0efca42

Browse files
committed
feat: DropRateCache업데이트가 되지 않으면 스프링 실행이 되지 않는 버그를 수정한다
1 parent 7dce5cd commit 0efca42

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/kotlin/org/gitanimals/gotcha/infra/DropRateCache.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.gitanimals.gotcha.infra
22

3+
import org.gitanimals.core.IdGenerator
4+
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
35
import org.gitanimals.gotcha.app.RenderApi
46
import org.gitanimals.gotcha.domain.DropRateClient
7+
import org.slf4j.LoggerFactory
8+
import org.slf4j.MDC
59
import org.springframework.boot.context.event.ApplicationStartedEvent
610
import org.springframework.context.event.EventListener
711
import org.springframework.scheduling.annotation.Scheduled
@@ -12,6 +16,7 @@ class DropRateCache(
1216
private val renderApi: RenderApi,
1317
) : DropRateClient {
1418

19+
private val logger = LoggerFactory.getLogger(this::class.simpleName)
1520
private var dropRates = mutableMapOf<String, Double>()
1621

1722
override fun getDropRate(name: String): Double = dropRates[name] ?: DEFAULT_DROP_RATE
@@ -27,7 +32,15 @@ class DropRateCache(
2732
}
2833

2934
fun updateDropRate() {
30-
val personas = renderApi.getAllPersonas().personas
35+
val personas = runCatching {
36+
MDC.put(TRACE_ID, IdGenerator.generate().toString())
37+
renderApi.getAllPersonas().personas
38+
}.getOrElse {
39+
logger.error("Fail to cache drop rate retry after 10 minutes", it)
40+
emptyList()
41+
}.also {
42+
MDC.remove(TRACE_ID)
43+
}
3144

3245
personas.forEach { persona ->
3346
dropRates[persona.type] = persona.dropRate.replace("%", "").toDouble()

0 commit comments

Comments
 (0)