From 322981c9301f9b3718ccc0e34d877892281044bb Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 2 Jan 2024 23:06:16 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=9F=AC=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/ScheduleController.java | 41 ------------------- .../server/scheduler/DiaryScheduler.java | 19 +++++++++ .../server/scheduler/MessageScheduler.java | 24 +++++++++++ 3 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/com/smeme/server/controller/ScheduleController.java create mode 100644 src/main/java/com/smeme/server/scheduler/DiaryScheduler.java create mode 100644 src/main/java/com/smeme/server/scheduler/MessageScheduler.java diff --git a/src/main/java/com/smeme/server/controller/ScheduleController.java b/src/main/java/com/smeme/server/controller/ScheduleController.java deleted file mode 100644 index a2a25470..00000000 --- a/src/main/java/com/smeme/server/controller/ScheduleController.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.smeme.server.controller; - -import java.time.LocalDateTime; - -import com.smeme.server.config.ValueConfig; -import com.smeme.server.repository.diary.DiaryRepository; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.web.bind.annotation.RestController; - -import com.smeme.server.service.DiaryService; -import com.smeme.server.service.MessageService; - -import lombok.RequiredArgsConstructor; - -@RestController -@EnableScheduling -@RequiredArgsConstructor -public class ScheduleController { - - private final MessageService messageService; - private final DiaryService diaryService; - private final ValueConfig valueConfig; - private final DiaryRepository diaryRepository; - -// @Scheduled(cron = "0 0/30 * * * *") - public void pushMessage() throws InterruptedException { - Thread.sleep(1000); - messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); - } - - @Scheduled(cron = "0 0 0 * * *") - public void deleteExpiredDiaries() { - diaryService.deleteExpiredDiary(); - } - - //TODO: DB 작업 과정 중 삭제된 Diary 데이터 이동 - public void copyToDeletedDiary() { - diaryRepository.findDeleted().forEach(diary -> diaryService.delete(diary.getId())); - } -} diff --git a/src/main/java/com/smeme/server/scheduler/DiaryScheduler.java b/src/main/java/com/smeme/server/scheduler/DiaryScheduler.java new file mode 100644 index 00000000..b59d1db1 --- /dev/null +++ b/src/main/java/com/smeme/server/scheduler/DiaryScheduler.java @@ -0,0 +1,19 @@ +package com.smeme.server.scheduler; + +import com.smeme.server.service.DiaryService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@EnableScheduling +@RequiredArgsConstructor +public class DiaryScheduler { + private final DiaryService diaryService; + + @Scheduled(cron = "0 0 0 * * *") + public void deleteExpiredDiaries() { + diaryService.deleteExpiredDiary(); + } +} diff --git a/src/main/java/com/smeme/server/scheduler/MessageScheduler.java b/src/main/java/com/smeme/server/scheduler/MessageScheduler.java new file mode 100644 index 00000000..275263a4 --- /dev/null +++ b/src/main/java/com/smeme/server/scheduler/MessageScheduler.java @@ -0,0 +1,24 @@ +package com.smeme.server.scheduler; + +import com.smeme.server.config.ValueConfig; +import com.smeme.server.service.MessageService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +@EnableScheduling +@RequiredArgsConstructor +public class MessageScheduler { + private final MessageService messageService; + private final ValueConfig valueConfig; + + @Scheduled(cron = "${fcm.cron_expression}") + public void pushMessage() throws InterruptedException { + Thread.sleep(1000); + messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); + } +}