Skip to content

Commit

Permalink
[FIX] 스케줄러 패키지 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss committed Jan 2, 2024
1 parent c329329 commit 322981c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
41 changes: 0 additions & 41 deletions src/main/java/com/smeme/server/controller/ScheduleController.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/main/java/com/smeme/server/scheduler/DiaryScheduler.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/smeme/server/scheduler/MessageScheduler.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 322981c

Please sign in to comment.