feat(audio-recommendation): 추천 snapshot 스케줄러를 추가한다

This commit is contained in:
2026-06-23 21:05:56 +09:00
parent 1c7bac3a73
commit 6a6deb33a3
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package kr.co.vividnext.sodalive.v2.audio.recommendation.adapter.out.scheduler
import kr.co.vividnext.sodalive.v2.audio.recommendation.application.AudioRecommendationSnapshotRefreshService
import org.redisson.api.RedissonClient
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.util.concurrent.TimeUnit
@Component
class AudioRecommendationSnapshotScheduler(
private val refreshService: AudioRecommendationSnapshotRefreshService,
private val redissonClient: RedissonClient
) {
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
fun refreshDailySnapshots() {
val lock = redissonClient.getLock(LOCK_KEY)
try {
if (lock.tryLock(0, -1, TimeUnit.SECONDS)) {
refreshService.refreshDailySnapshots()
}
} finally {
if (lock.isHeldByCurrentThread) {
lock.unlock()
}
}
}
companion object {
const val LOCK_KEY = "lock:audio-recommendation-snapshot-refresh"
}
}