🚧 定时任务.

This commit is contained in:
lijiahangmax
2024-03-27 01:07:47 +08:00
parent eb75877ea6
commit c23eb89e7e
5 changed files with 103 additions and 9 deletions

View File

@@ -25,19 +25,21 @@ public interface AutoConfigureOrderConst {
int FRAMEWORK_LOG = Integer.MIN_VALUE + 1500;
int FRAMEWORK_JOB = Integer.MIN_VALUE + 1600;
int FRAMEWORK_SWAGGER = Integer.MIN_VALUE + 1600;
int FRAMEWORK_SWAGGER = Integer.MIN_VALUE + 1700;
int FRAMEWORK_DATASOURCE = Integer.MIN_VALUE + 1700;
int FRAMEWORK_DATASOURCE = Integer.MIN_VALUE + 1800;
int FRAMEWORK_MYBATIS = Integer.MIN_VALUE + 1800;
int FRAMEWORK_MYBATIS = Integer.MIN_VALUE + 1900;
int FRAMEWORK_REDIS = Integer.MIN_VALUE + 1900;
int FRAMEWORK_REDIS = Integer.MIN_VALUE + 2000;
int FRAMEWORK_REDIS_CACHE = Integer.MIN_VALUE + 1950;
int FRAMEWORK_REDIS_CACHE = Integer.MIN_VALUE + 2050;
int FRAMEWORK_STORAGE = Integer.MIN_VALUE + 2000;
int FRAMEWORK_STORAGE = Integer.MIN_VALUE + 2100;
int FRAMEWORK_JOB = Integer.MIN_VALUE + 2100;
int FRAMEWORK_JOB_QUARTZ = Integer.MIN_VALUE + 2150;
int FRAMEWORK_MONITOR = Integer.MIN_VALUE + 2200;

View File

@@ -32,6 +32,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,54 @@
package com.orion.ops.framework.job.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import org.quartz.Scheduler;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
import javax.sql.DataSource;
/**
* quartz 配置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/3/27 0:58
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_JOB_QUARTZ)
public class OrionQuartzAutoConfiguration {
/**
* @return 任务工厂
*/
@Bean
public SpringBeanJobFactory jobFactory() {
return new SpringBeanJobFactory();
}
/**
* @param dataSource dataSource
* @param jobFactory jobFactory
* @return 调度器工厂
*/
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, SpringBeanJobFactory jobFactory) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
factory.setJobFactory(jobFactory);
return factory;
}
/**
* @param schedulerFactoryBean 调度器工厂
* @return 调度器
*/
@Bean(initMethod = "start")
public Scheduler scheduler(SchedulerFactoryBean schedulerFactoryBean) {
return schedulerFactoryBean.getScheduler();
}
}

View File

@@ -1 +1,2 @@
com.orion.ops.framework.job.config.OrionSchedulerAutoConfiguration
com.orion.ops.framework.job.config.OrionSchedulerAutoConfiguration
com.orion.ops.framework.job.config.OrionQuartzAutoConfiguration