test #243
|
@ -34,7 +34,6 @@ dependencies {
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
implementation("org.springframework.retry:spring-retry")
|
implementation("org.springframework.retry:spring-retry")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
implementation("org.redisson:redisson-spring-boot-starter:3.17.7")
|
|
||||||
|
|
||||||
// jwt
|
// jwt
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package kr.co.vividnext.sodalive.configs
|
package kr.co.vividnext.sodalive.configs
|
||||||
|
|
||||||
import org.redisson.Redisson
|
|
||||||
import org.redisson.api.RedissonClient
|
|
||||||
import org.redisson.config.Config
|
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.cache.annotation.EnableCaching
|
import org.springframework.cache.annotation.EnableCaching
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
|
@ -29,17 +26,6 @@ class RedisConfig(
|
||||||
@Value("\${spring.redis.port}")
|
@Value("\${spring.redis.port}")
|
||||||
private val port: Int
|
private val port: Int
|
||||||
) {
|
) {
|
||||||
@Bean
|
|
||||||
fun redissonClient(): RedissonClient {
|
|
||||||
val config = Config()
|
|
||||||
config.useSingleServer()
|
|
||||||
.setAddress("redis://$host:$port")
|
|
||||||
.setConnectionMinimumIdleSize(1) // 최소 유휴 연결: 1
|
|
||||||
.setConnectionPoolSize(5) // 최대 연결 풀 크기: 5
|
|
||||||
|
|
||||||
return Redisson.create(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun redisConnectionFactory(): RedisConnectionFactory {
|
fun redisConnectionFactory(): RedisConnectionFactory {
|
||||||
val clientConfiguration = LettuceClientConfiguration.builder()
|
val clientConfiguration = LettuceClientConfiguration.builder()
|
||||||
|
|
|
@ -1,32 +1,15 @@
|
||||||
package kr.co.vividnext.sodalive.scheduler
|
package kr.co.vividnext.sodalive.scheduler
|
||||||
|
|
||||||
import kr.co.vividnext.sodalive.content.AudioContentService
|
import kr.co.vividnext.sodalive.content.AudioContentService
|
||||||
import org.redisson.api.RedissonClient
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled
|
import org.springframework.scheduling.annotation.Scheduled
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class AudioContentReleaseSchedulerService(
|
class AudioContentReleaseSchedulerService(
|
||||||
private val redissonClient: RedissonClient,
|
|
||||||
private val audioContentService: AudioContentService
|
private val audioContentService: AudioContentService
|
||||||
) {
|
) {
|
||||||
@Scheduled(fixedRate = 1000 * 60 * 5)
|
@Scheduled(cron = "0 0/15 * * * *")
|
||||||
fun release() {
|
fun release() {
|
||||||
val lock = redissonClient.getLock("lock:audioContentRelease")
|
audioContentService.releaseContent()
|
||||||
|
|
||||||
if (lock.tryLock(10, TimeUnit.SECONDS)) {
|
|
||||||
try {
|
|
||||||
println("락을 획득하여 배포를 시작합니다.")
|
|
||||||
audioContentService.releaseContent()
|
|
||||||
} finally {
|
|
||||||
if (lock.isHeldByCurrentThread) {
|
|
||||||
lock.unlock()
|
|
||||||
println("락 해제")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println("락을 획득하지 못해서 배포를 건너뜁니다")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue