서베이지에서는 활성 패널의 수에 따라 수집 가능한 최대 응답수가 달라지게 된다.
이에 따라 서베이지는 10일 단위로 활성 패널의 현황을 자동 업데이트하는 기능을 도입하기로 결정했다.
오늘은 Spring Boot의 @Scheduled을 이용하여 10일마다 실행되는 scheduled task를 만들어 볼 것이다.
1. @EnableScheduling
스프링의 scheduled task 실행을 가능하게 하는 어노테이션이며, 메인 Application에 붙여준다.
@SpringBootApplication
@EnableScheduling
public class SurveasyApplication {
public static void main(String[] args) {
SpringApplication.run(SurveasyApplication.class, args);
}
}
2. @Scheduled
구체적인 스케쥴링 작업을 설정하는 어노테이션이며, 메소드에 붙여준다.
실행 주기를 설정하는 방법은 크게 cron, fixedDelay, fixedRate가 있다.
2-1. cron
* 의 위치별로 초, 분, 시간, 일, 월, 요일을 나타낸다.
* * * * * *
초(0-59) 분(0-59) 시간(0-23) 일(1-31) 월(1-12) 요일(0-7)
[참고] 0 = 7 = 일요일
[예제] 0 15 10 ? * * (매일 10:15:00), 0 30 10 1/8 * ? (매달 1일을 시작으로 8일 주기로, 10:30:00)
@Scheduled(cron = 0 15 10 ? * *)
2-2. fixedDelay
메소드 종료 시점 ~ 다음 메소드 시작 시점 주기 (milliseconds)

@Scheduled(fixedDelay = 1000)
2-3. fixedRate
메소드가 시작되는 시점의 주기 (milliseconds)

@Scheduled(fixedRate = 1000)
'Spring > Spring Boot' 카테고리의 다른 글
[Spring Boot - Zoom] 회의실 자동 생성 #1. OAuth2.0 (0) | 2024.01.03 |
---|---|
[Spring Boot - Firebase] 연동하기 (0) | 2023.10.28 |
[Spring Boot - JPA] Entity의 Default Value 지정하기 (0) | 2023.08.21 |
[Spring boot - OAuth2] Naver Login 구현 #2 (0) | 2023.03.04 |
[Spring boot - OAuth2] Naver Login 구현 #1 (0) | 2023.03.04 |