feat(audio-recommendation): 추천 snapshot 스케줄러를 추가한다
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user