feat(ranking): 스냅샷 스케줄러 lock을 적용한다

This commit is contained in:
2026-06-08 20:19:46 +09:00
parent 8ab4d0ae84
commit f384ee0dd5
2 changed files with 67 additions and 7 deletions

View File

@@ -1,15 +1,29 @@
package kr.co.vividnext.sodalive.v2.ranking.adapter.out.scheduler
import kr.co.vividnext.sodalive.v2.ranking.application.CreatorRankingSnapshotRefreshService
import org.redisson.api.RedissonClient
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.util.concurrent.TimeUnit
@Component
class CreatorRankingSnapshotScheduler(
private val refreshService: CreatorRankingSnapshotRefreshService
private val refreshService: CreatorRankingSnapshotRefreshService,
private val redissonClient: RedissonClient
) {
@Scheduled(cron = "0 0 6 * * MON", zone = "Asia/Seoul")
@Scheduled(cron = "0 30 7 * * MON", zone = "Asia/Seoul")
fun refreshLastCompletedWeek() {
refreshService.refreshLastCompletedWeek()
val lockName = "lock:creator-ranking-snapshot-refresh"
val lock = redissonClient.getLock(lockName)
try {
if (lock.tryLock(0, -1, TimeUnit.SECONDS)) {
refreshService.refreshLastCompletedWeek()
}
} finally {
if (lock.isHeldByCurrentThread) {
lock.unlock()
}
}
}
}