|
@@ -8,10 +8,8 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.concurrent.Future;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
* @author ZhangXianyu
|
|
@@ -33,13 +31,11 @@ public class OrderCostMonitorAlarmTask {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- * 任务每10分钟运行一次
|
|
|
- */
|
|
|
- @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
public void run() {
|
|
|
+ log.info("订单与消耗监控告警定时任务开始.");
|
|
|
Future<?> future = taskScheduler.submit(() -> {
|
|
|
- log.info("订单与消耗监控告警定时任务开始.");
|
|
|
|
|
|
if (!run) {
|
|
|
return;
|
|
@@ -71,4 +67,50 @@ public class OrderCostMonitorAlarmTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ * 任务每10分钟运行一次
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
+ public void runTask(){
|
|
|
+ log.info("订单与消耗监控告警定时任务开始.");
|
|
|
+ ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
|
|
+ Runnable task = ()->{
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ if (now.getHour() == 0 && now.getMinute() <= 30) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ orderCostMonitorAlarmService.monitorDataStatus();
|
|
|
+
|
|
|
+ orderCostMonitorAlarmService.monitorHeadCostStatus();
|
|
|
+
|
|
|
+ orderCostMonitorAlarmService.monitorTencentCostStatus();
|
|
|
+ log.info("订单与消耗监控告警定时任务结束.");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("定时任务订单与消耗监控告警超时", e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ scheduler.submit(task);
|
|
|
+
|
|
|
+ scheduler.shutdown();
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (!scheduler.awaitTermination(120, TimeUnit.SECONDS)) {
|
|
|
+ log.info("线程池关闭超时,可能有任务未完成");
|
|
|
+ }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+
|
|
|
+ log.info("线程池关闭时当前线程被中断");
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Runnable> notStartedTasks = scheduler.shutdownNow();
|
|
|
+ log.info("已取消 " + notStartedTasks.size() + " 个任务");
|
|
|
+ }
|
|
|
+
|
|
|
}
|