ApplicationScheduler.java 3.9 KB

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