智慧保安后台管理-外网项目备份
zhongrj
2023-09-17 8853292babb2ad94de4a3207966f1e83b767cd2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.springblade.modules.quartz.config;
 
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springblade.modules.quartz.entity.ScheduledJob;
import org.springblade.modules.quartz.event.ScheduleEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
 
/**
 * 该类将会被org.springframework.scheduling.quartz.SpringBeanJobFactory 实例化
 * 并使@Autowired 生效
 * @author zhongrj
 * @since 2022-03-17
 */
@Slf4j
@DisallowConcurrentExecution
public class QuartzJob implements Job {
 
    @Autowired
    private ApplicationEventPublisher eventPublisher;
 
    /**
     * 任务调度参数key
     */
    public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";
 
    @Override
    @SneakyThrows
    public void execute(JobExecutionContext jobExecutionContext){
        ScheduledJob scheduledCron = (ScheduledJob)jobExecutionContext.getMergedJobDataMap().get(JOB_PARAM_KEY);
        eventPublisher.publishEvent(new ScheduleEvent(scheduledCron));
    }
}