스프링 스케줄러를 이용하여 콘텐츠 예약 오픈 설정

This commit is contained in:
2024-12-02 08:22:16 +09:00
parent 4097e5a133
commit 05592f94b9
6 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package kr.co.vividnext.sodalive.scheduler
import kr.co.vividnext.sodalive.content.AudioContentService
import org.redisson.api.RedissonClient
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.util.concurrent.TimeUnit
@Service
class AudioContentReleaseSchedulerService(
private val redissonClient: RedissonClient,
private val audioContentService: AudioContentService
) {
@Scheduled(fixedRate = 1000 * 60 * 5)
fun release() {
val lock = redissonClient.getLock("lock:audioContentRelease")
if (lock.tryLock(10, TimeUnit.SECONDS)) {
try {
println("락을 획득하여 배포를 시작합니다.")
audioContentService.releaseContent()
} finally {
if (lock.isHeldByCurrentThread) {
lock.unlock()
println("락 해제")
}
}
} else {
println("락을 획득하지 못해서 배포를 건너뜁니다")
}
}
}