ApplicationScheduler.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.its.rota.server.scheduler;
  2. import com.its.app.common.utils.Elapsed;
  3. import com.its.rota.server.config.SchedulingConfig;
  4. import com.its.rota.server.process.dbms.DbmsData;
  5. import com.its.rota.server.process.dbms.DbmsDataProcess;
  6. import com.its.rota.server.repository.ApplicationRepository;
  7. import com.its.rota.server.service.ItsRotaServerService;
  8. import lombok.RequiredArgsConstructor;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.scheduling.annotation.Async;
  11. import org.springframework.scheduling.annotation.EnableScheduling;
  12. import org.springframework.scheduling.annotation.Scheduled;
  13. import org.springframework.stereotype.Component;
  14. import javax.annotation.PreDestroy;
  15. @Slf4j
  16. @RequiredArgsConstructor
  17. @EnableScheduling
  18. @Component
  19. public class ApplicationScheduler {
  20. private final SchedulingConfig config;
  21. private final DbmsDataProcess dbmsDataProcess;
  22. private final ItsRotaServerService itsRotaServerService;
  23. private final DbmsData delSndLog = new DbmsData(null, DbmsData.DBMS_DATA_DELETE_SND_LOG, null);
  24. private final DbmsData delSndIncident = new DbmsData(null, DbmsData.DBMS_DATA_DELETE_SND_INCIDENT, null);
  25. @PreDestroy
  26. public void onShutDown() {
  27. }
  28. // 초(0-59) 분(0-59) 시간(0-23) 일(1-31) 월(1-12) 요일(0-6) (0: 일, 1: 월, 2:화, 3:수, 4:목, 5:금, 6:토)
  29. @Async
  30. @Scheduled(cron = "0 * * * * *") // 1분 주기 작업 실행
  31. public void unitSystSchedule() {
  32. // Elapsed elapsed = new Elapsed();
  33. // log.info("ApplicationScheduler.unitSystSchedule: start.");
  34. // try {
  35. // this.unitSystService.updateUnitSystStts(true);
  36. // log.info("ApplicationScheduler.unitSystSchedule: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
  37. // }
  38. // catch(Exception e) {
  39. // log.error("ApplicationScheduler.unitSystSchedule: Exception {}", e.getMessage());
  40. // }
  41. }
  42. @Async
  43. @Scheduled(cron = "${application.scheduler.delete-snd-incident:0/40 3 * * * *}")
  44. public void deleteSndIncident() {
  45. if (!this.config.isUseSndIncident()) {
  46. return;
  47. }
  48. Elapsed elapsed = new Elapsed();
  49. log.info("ApplicationScheduler.deleteSndIncident: start.");
  50. try {
  51. this.delSndIncident.setCenter(ApplicationRepository.center);
  52. this.dbmsDataProcess.add(this.delSndIncident);
  53. log.info("ApplicationScheduler.deleteSndIncident: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
  54. }
  55. catch(Exception e) {
  56. log.error("ApplicationScheduler.deleteSndIncident: Exception {}", e.getMessage());
  57. }
  58. }
  59. @Async
  60. @Scheduled(cron = "${application.scheduler.delete-snd-log:0/40 3 * * * *}")
  61. public void deleteSndLog() {
  62. if (!this.config.isUseSndLog()) {
  63. return;
  64. }
  65. Elapsed elapsed = new Elapsed();
  66. log.info("ApplicationScheduler.deleteSndLog: start.");
  67. try {
  68. this.delSndLog.setCenter(ApplicationRepository.center);
  69. this.dbmsDataProcess.add(this.delSndLog);
  70. log.info("ApplicationScheduler.deleteSndLog: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
  71. }
  72. catch(Exception e) {
  73. log.error("ApplicationScheduler.deleteSndLog: Exception {}", e.getMessage());
  74. }
  75. }
  76. @Async
  77. @Scheduled(cron = "0 * * * * *") // 1분 주기 작업 실행
  78. public void checkSendIncident() {
  79. // Elapsed elapsed = new Elapsed();
  80. // log.info("ApplicationScheduler.checkSendIncident: start.");
  81. // try {
  82. // this.itsRotaServerService.checkSendIncident();
  83. // log.info("ApplicationScheduler.checkSendIncident: {}", Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
  84. // }
  85. // catch(Exception e) {
  86. // log.error("ApplicationScheduler.checkSendIncident: Exception {}", e.getMessage());
  87. // }
  88. }
  89. @Async
  90. @Scheduled(cron = "0/10 * * * * *") // 10초 주기 작업 실행
  91. public void checkSendTraffic() {
  92. // Elapsed elapsed = new Elapsed();
  93. // log.info("ApplicationScheduler.checkSendTraffic: start.");
  94. try {
  95. int result = this.itsRotaServerService.checkSendTraffic();
  96. // log.info("ApplicationScheduler.checkSendTraffic: result: {}, {}", result, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
  97. }
  98. catch(Exception e) {
  99. log.error("ApplicationScheduler.checkSendTraffic: Exception {}", e.getMessage());
  100. }
  101. }
  102. }