-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from chanmin-00/issue/53-scheduled
✨ [Feat] 스케줄링을 사용하여 영화 정보 업데이트 자동화 구축
- Loading branch information
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/WatchWithMe/global/config/SchedulerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package WatchWithMe.global.config; | ||
|
||
import WatchWithMe.global.exception.GlobalException; | ||
import WatchWithMe.global.exception.code.GlobalErrorCode; | ||
import WatchWithMe.service.MovieService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
|
||
@Slf4j | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class SchedulerConfig implements SchedulingConfigurer { | ||
|
||
private final int POOL_SIZE = 10; // 스레드 풀 사이즈 | ||
private final MovieService movieService; | ||
|
||
@Scheduled(initialDelay=1000, fixedDelay=60000 * 5) // 5분 마다 수행 | ||
public void updateMovieList() { | ||
try { | ||
movieService.updateMovieList(); | ||
log.info("영화 정보 업데이트 완료"); | ||
} catch (Exception e) { | ||
throw new GlobalException(GlobalErrorCode._INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
// 여러 개의 스레드 동시 처리 | ||
@Override | ||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | ||
final ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); | ||
threadPoolTaskScheduler.setPoolSize(POOL_SIZE); | ||
threadPoolTaskScheduler.setThreadNamePrefix("test-scheduled-task-pool-"); | ||
threadPoolTaskScheduler.initialize(); | ||
|
||
taskRegistrar.setTaskScheduler(threadPoolTaskScheduler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters