ng-tracker/src/main/java/ru/ulstu/paper/service/PaperScheduler.java
2018-11-21 15:40:20 +04:00

45 lines
1.7 KiB
Java

package ru.ulstu.paper.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class PaperScheduler {
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
private final Logger log = LoggerFactory.getLogger(PaperScheduler.class);
private final PaperNotificationService paperNotificationService;
private final PaperService paperService;
public PaperScheduler(PaperNotificationService paperNotificationService,
PaperService paperService) {
this.paperNotificationService = paperNotificationService;
this.paperService = paperService;
}
@Scheduled(cron = "0 0 8 * 1 ?")
public void checkDeadlineBeforeWeek() {
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
}
@Scheduled(cron = "0 0 8 * * ?")
public void checkDeadlineAfterWeek() {
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
}
@Scheduled(cron = "0 0 6 * * ?")
public void closeFailedPapers() {
log.debug("PaperScheduler.closeFailedPapers started");
paperService.closeFailedPapers();
log.debug("PaperScheduler.closeFailedPapers finished");
}
}