Skip to content

Commit 6e572e6

Browse files
committed
스케줄러 예외 처리
1 parent a3a60a0 commit 6e572e6

1 file changed

Lines changed: 40 additions & 23 deletions

File tree

src/main/java/devkor/com/teamcback/domain/operatingtime/scheduler/OperatingScheduler.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,62 @@ public class OperatingScheduler {
3030
private static Boolean isEvenWeek = null;
3131

3232
@Scheduled(cron = "0 0 0 * * *") // 매일 자정마다
33-
// @EventListener(ApplicationReadyEvent.class)
33+
@EventListener(ApplicationReadyEvent.class)
3434
public void updateOperatingTime() {
35-
setState();
36-
log.info("운영 시간 업데이트");
3735

38-
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
39-
operatingService.updateOperatingTime(dayOfWeek, isHoliday, isVacation, isEvenWeek);
40-
return null;
41-
});
36+
try{
37+
setState();
38+
log.info("운영 시간 업데이트");
39+
40+
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
41+
operatingService.updateOperatingTime(dayOfWeek, isHoliday, isVacation, isEvenWeek);
42+
return null;
43+
});
44+
} catch (Exception e) {
45+
log.info("updateOperatingTime() 작업 실패: {}", e.getMessage(), e);
46+
}
4247
}
4348

4449

45-
// @Scheduled(cron = "30 35 * * * *") // 테스트용
50+
// @EventListener(ApplicationReadyEvent.class) // 테스트용
4651
@Scheduled(cron = "0 */10 9-18 * * *") // 10분마다
4752
public void updateOperatingDuringPeakHour() {
48-
log.info("운영 여부 업데이트");
49-
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
50-
operatingService.updateIsOperating(LocalTime.now(), dayOfWeek, isHoliday, isVacation, isEvenWeek);
51-
return null;
52-
});
53+
try{
54+
log.info("운영 여부 업데이트");
55+
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
56+
operatingService.updateIsOperating(LocalTime.now(), dayOfWeek, isHoliday, isVacation, isEvenWeek);
57+
return null;
58+
});
59+
} catch (Exception e) {
60+
log.info("updateOperatingDuringPeakHour() 작업 실패: {}", e.getMessage(), e);
61+
}
5362
}
5463

5564
@Scheduled(cron = "0 0,30 0-8,19-23 * * *") // 30분마다
5665
public void updateOperating() {
57-
log.info("운영 여부 업데이트");
58-
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
59-
operatingService.updateIsOperating(LocalTime.now(), dayOfWeek, isHoliday, isVacation, isEvenWeek);
60-
return null;
61-
});
66+
try{
67+
log.info("운영 여부 업데이트");
68+
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
69+
operatingService.updateIsOperating(LocalTime.now(), dayOfWeek, isHoliday, isVacation, isEvenWeek);
70+
return null;
71+
});
72+
} catch (Exception e) {
73+
log.info("updateOperating() 작업 실패: {}", e.getMessage(), e);
74+
}
6275
}
6376

6477
// 장소 운영 시간 저장 - 건물의 운영 시간에 변동이 있을 경우 1회 작동
6578
@EventListener(ApplicationReadyEvent.class)
6679
public void updatePlaceOperatingTime() {
67-
log.info("장소 운영 시간 업데이트");
68-
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
69-
operatingService.updatePlaceOperatingTime();
70-
return null;
71-
});
80+
try{
81+
log.info("장소 운영 시간 업데이트");
82+
redisLockUtil.executeWithLock("lock", 1, 300, () -> {
83+
operatingService.updatePlaceOperatingTime();
84+
return null;
85+
});
86+
} catch (Exception e) {
87+
log.info("updatePlaceOperatingTime() 작업 실패: {}", e.getMessage(), e);
88+
}
7289
}
7390

7491
private void setState() {

0 commit comments

Comments
 (0)