package com.its.rota.server.scheduler; import com.its.app.common.utils.Elapsed; import com.its.rota.server.config.SchedulingConfig; import com.its.rota.server.process.dbms.DbmsData; import com.its.rota.server.process.dbms.DbmsDataProcess; import com.its.rota.server.repository.ApplicationRepository; import com.its.rota.server.service.ItsRotaServerService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.PreDestroy; @Slf4j @RequiredArgsConstructor @EnableScheduling @Component public class ApplicationScheduler { private final SchedulingConfig config; private final DbmsDataProcess dbmsDataProcess; private final ItsRotaServerService itsRotaServerService; private final DbmsData delSndLog = new DbmsData(null, DbmsData.DBMS_DATA_DELETE_SND_LOG, null); private final DbmsData delSndIncident = new DbmsData(null, DbmsData.DBMS_DATA_DELETE_SND_INCIDENT, null); @PreDestroy public void onShutDown() { } // 초(0-59) 분(0-59) 시간(0-23) 일(1-31) 월(1-12) 요일(0-6) (0: 일, 1: 월, 2:화, 3:수, 4:목, 5:금, 6:토) @Async @Scheduled(cron = "0 * * * * *") // 1분 주기 작업 실행 public void unitSystSchedule() { // Elapsed elapsed = new Elapsed(); // log.info("ApplicationScheduler.unitSystSchedule: start."); // try { // this.unitSystService.updateUnitSystStts(true); // log.info("ApplicationScheduler.unitSystSchedule: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds())); // } // catch(Exception e) { // log.error("ApplicationScheduler.unitSystSchedule: Exception {}", e.getMessage()); // } } @Async @Scheduled(cron = "${application.scheduler.delete-snd-incident:0/40 3 * * * *}") public void deleteSndIncident() { if (!this.config.isUseSndIncident()) { return; } Elapsed elapsed = new Elapsed(); log.info("ApplicationScheduler.deleteSndIncident: start."); try { this.delSndIncident.setCenter(ApplicationRepository.center); this.dbmsDataProcess.add(this.delSndIncident); log.info("ApplicationScheduler.deleteSndIncident: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds())); } catch(Exception e) { log.error("ApplicationScheduler.deleteSndIncident: Exception {}", e.getMessage()); } } @Async @Scheduled(cron = "${application.scheduler.delete-snd-log:0/40 3 * * * *}") public void deleteSndLog() { if (!this.config.isUseSndLog()) { return; } Elapsed elapsed = new Elapsed(); log.info("ApplicationScheduler.deleteSndLog: start."); try { this.delSndLog.setCenter(ApplicationRepository.center); this.dbmsDataProcess.add(this.delSndLog); log.info("ApplicationScheduler.deleteSndLog: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds())); } catch(Exception e) { log.error("ApplicationScheduler.deleteSndLog: Exception {}", e.getMessage()); } } @Async @Scheduled(cron = "0 * * * * *") // 1분 주기 작업 실행 public void checkSendIncident() { // Elapsed elapsed = new Elapsed(); // log.info("ApplicationScheduler.checkSendIncident: start."); // try { // this.itsRotaServerService.checkSendIncident(); // log.info("ApplicationScheduler.checkSendIncident: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds())); // } // catch(Exception e) { // log.error("ApplicationScheduler.checkSendIncident: Exception {}", e.getMessage()); // } } @Async @Scheduled(cron = "0/10 * * * * *") // 10초 주기 작업 실행 public void checkSendTraffic() { // Elapsed elapsed = new Elapsed(); // log.info("ApplicationScheduler.checkSendTraffic: start."); try { int result = this.itsRotaServerService.checkSendTraffic(); // log.info("ApplicationScheduler.checkSendTraffic: result: {}, {}", result, Elapsed.elapsedTimeStr(elapsed.nanoSeconds())); } catch(Exception e) { log.error("ApplicationScheduler.checkSendTraffic: Exception {}", e.getMessage()); } } }