From c1748001d5f2fc77647ac7d8aef13f25433362be Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 2 Dec 2024 08:58:54 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=98=ED=85=90=EC=B8=A0=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EC=98=A4=ED=94=88=20=EC=84=A4=EC=A0=95=20-=20?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=A4=84=EB=9F=AC=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vividnext/sodalive/SodaLiveApplication.kt | 2 -- ....kt => AudioContentReleaseSchedulerOnly.kt} | 6 +++--- .../sodalive/configs/SchedulerConfig.kt | 18 ++++++++++++++++++ .../sodalive/content/AudioContentService.kt | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-) rename src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/{SchedulerOnly.kt => AudioContentReleaseSchedulerOnly.kt} (75%) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/configs/SchedulerConfig.kt diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/SodaLiveApplication.kt b/src/main/kotlin/kr/co/vividnext/sodalive/SodaLiveApplication.kt index d160bf6..78fe613 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/SodaLiveApplication.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/SodaLiveApplication.kt @@ -4,10 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.retry.annotation.EnableRetry import org.springframework.scheduling.annotation.EnableAsync -import org.springframework.scheduling.annotation.EnableScheduling @SpringBootApplication -@EnableScheduling @EnableAsync @EnableRetry class SodaLiveApplication diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/SchedulerOnly.kt b/src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/AudioContentReleaseSchedulerOnly.kt similarity index 75% rename from src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/SchedulerOnly.kt rename to src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/AudioContentReleaseSchedulerOnly.kt index 2c29ee8..28340bc 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/SchedulerOnly.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/common/annotation/AudioContentReleaseSchedulerOnly.kt @@ -6,13 +6,13 @@ import org.springframework.stereotype.Component @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.RUNTIME) -annotation class SchedulerOnly +annotation class AudioContentReleaseSchedulerOnly @Aspect @Component class SchedulerOnlyAspect { - @Before("@annotation(SchedulerOnly)") + @Before("@annotation(AudioContentReleaseSchedulerOnly)") fun checkSchedulerAccess() { if (!isSchedulerThread()) { throw IllegalStateException("잘못된 접근입니다.") @@ -21,6 +21,6 @@ class SchedulerOnlyAspect { private fun isSchedulerThread(): Boolean { // 스케줄러 스레드 여부를 판단하는 간단한 로직 - return Thread.currentThread().name.contains("scheduler") + return Thread.currentThread().name.contains("AudioContentRelease-Scheduler") } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/configs/SchedulerConfig.kt b/src/main/kotlin/kr/co/vividnext/sodalive/configs/SchedulerConfig.kt new file mode 100644 index 0000000..116acc6 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/configs/SchedulerConfig.kt @@ -0,0 +1,18 @@ +package kr.co.vividnext.sodalive.configs + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.scheduling.annotation.EnableScheduling +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler + +@Configuration +@EnableScheduling +class SchedulerConfig { + @Bean + fun taskScheduler(): ThreadPoolTaskScheduler { + val scheduler = ThreadPoolTaskScheduler() + scheduler.poolSize = 2 + scheduler.setThreadNamePrefix("AudioContentRelease-Scheduler-") + return scheduler + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentService.kt index 1902782..05f9738 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentService.kt @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront import kr.co.vividnext.sodalive.aws.s3.S3Uploader import kr.co.vividnext.sodalive.common.SodaException -import kr.co.vividnext.sodalive.common.annotation.SchedulerOnly +import kr.co.vividnext.sodalive.common.annotation.AudioContentReleaseSchedulerOnly import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag import kr.co.vividnext.sodalive.content.hashtag.HashTag @@ -403,7 +403,7 @@ class AudioContentService( } } - @SchedulerOnly + @AudioContentReleaseSchedulerOnly @Transactional fun releaseContent() { val notReleasedAudioContent = repository.getNotReleaseContent()