feat(content-ranking): 랭킹 스냅샷 스케줄러를 추가한다

This commit is contained in:
2026-06-24 19:02:39 +09:00
parent abeffb0a4f
commit 7ec19e3c8c
2 changed files with 127 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
package kr.co.vividnext.sodalive.v2.content.ranking.adapter.out.scheduler
import kr.co.vividnext.sodalive.v2.content.ranking.application.AudioRankingSnapshotJobService
import kr.co.vividnext.sodalive.v2.content.ranking.domain.AudioRankingType
import org.redisson.api.RedissonClient
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.util.concurrent.TimeUnit
@Component
class AudioRankingSnapshotScheduler(
private val jobService: AudioRankingSnapshotJobService,
private val redissonClient: RedissonClient
) {
@Scheduled(cron = "0 0 2 * * MON", zone = "Asia/Seoul")
fun refreshWeeklyPopular() {
refresh(AudioRankingType.WEEKLY_POPULAR)
}
@Scheduled(cron = "0 0 3 * * MON", zone = "Asia/Seoul")
fun refreshRising() {
refresh(AudioRankingType.RISING)
}
@Scheduled(cron = "0 0 4 * * MON", zone = "Asia/Seoul")
fun refreshRevenue() {
refresh(AudioRankingType.REVENUE)
}
@Scheduled(cron = "0 0 5 * * MON", zone = "Asia/Seoul")
fun refreshSalesCount() {
refresh(AudioRankingType.SALES_COUNT)
}
@Scheduled(cron = "0 0 6 * * MON", zone = "Asia/Seoul")
fun refreshCommentCount() {
refresh(AudioRankingType.COMMENT_COUNT)
}
@Scheduled(cron = "0 0 7 * * MON", zone = "Asia/Seoul")
fun refreshLikeCount() {
refresh(AudioRankingType.LIKE_COUNT)
}
private fun refresh(type: AudioRankingType) {
val lockName = "lock:content-ranking-snapshot-refresh:$type"
val lock = redissonClient.getLock(lockName)
try {
if (lock.tryLock(0, -1, TimeUnit.SECONDS)) {
jobService.refreshLastCompletedWeekByScheduledJob(type)
}
} finally {
if (lock.isHeldByCurrentThread) {
lock.unlock()
}
}
}
}