feat(ranking): 스냅샷 스케줄러 lock을 적용한다
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user