콘텐츠 예약 오픈 설정
- 분산락 제거, 서버가 여러대라면 여러번 호출될 수 있음
This commit is contained in:
@@ -1,32 +1,15 @@
|
||||
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)
|
||||
@Scheduled(cron = "0 0/15 * * * *")
|
||||
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("락을 획득하지 못해서 배포를 건너뜁니다")
|
||||
}
|
||||
audioContentService.releaseContent()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user