智慧保安后台管理-外网项目备份
钟日健
2022-03-17 f12960b94d949778001004c7af68ced0c3a3f28d
新增任务执行时间监控
4 files modified
20 ■■■■ changed files
deploy/deploy.yml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/quartz/controller/ScheduledController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/quartz/entity/ScheduledJob.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/quartz/listener/SchedulerListener.java 9 ●●●● patch | view | raw | blame | history
deploy/deploy.yml
@@ -25,7 +25,7 @@
      imagePullSecrets:
        - name: aliyun  #提前在项目下配置访问阿里云的账号密码
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/arsn/zhbaw:SNAPSHOT-7
        - image: registry.cn-hangzhou.aliyuncs.com/arsn/zhbaw:SNAPSHOT-8
#        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/zhba:SNAPSHOT-$BUILD_NUMBER
          imagePullPolicy: Always
          name: zhbaw
src/main/java/org/springblade/modules/quartz/controller/ScheduledController.java
@@ -147,7 +147,7 @@
    }
    /**
     * 定时任务恢复
     * 暂停定时任务
     * @param scheduledJob
     * @return
     */
src/main/java/org/springblade/modules/quartz/entity/ScheduledJob.java
@@ -81,4 +81,11 @@
    @JsonFormat(locale = "zh",pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;
    /**
     * 最近一次执行时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(locale = "zh",pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date activeTime;
}
src/main/java/org/springblade/modules/quartz/listener/SchedulerListener.java
@@ -3,11 +3,14 @@
import lombok.AllArgsConstructor;
import org.springblade.modules.quartz.entity.ScheduledJob;
import org.springblade.modules.quartz.event.ScheduleEvent;
import org.springblade.modules.quartz.service.ScheduledJobService;
import org.springblade.modules.quartz.util.SpringBeanTaskUtil;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
 * 异步监听定时任务事件,解决job线程无故丢失的问题
@@ -18,6 +21,9 @@
@AllArgsConstructor
@EnableAsync
public class SchedulerListener {
    private final ScheduledJobService scheduledJobService;
    @Async
    @EventListener(ScheduleEvent.class)
@@ -25,10 +31,11 @@
        //获取事件对象
        ScheduledJob scheduledJob = event.getScheduledJob();
        System.out.println("开始执行任务......");
        scheduledJob.setActiveTime(new Date());
        scheduledJobService.updateById(scheduledJob);
        //开始执行任务
        SpringBeanTaskUtil.invokeMethod(scheduledJob);
        System.out.println("任务执行结束......");
    }
}