🚧 定时任务.

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

View File

@@ -64,6 +64,34 @@ spring:
output:
ansi:
enabled: DETECT
quartz:
job-store-type: JDBC
overwrite-existing-jobs: false
jdbc:
initialize-schema: ALWAYS
properties:
org:
quartz:
scheduler:
# 实例 ID
instanceId: AUTO
instanceName: quartzScheduler
jobStore:
# 持久化配置
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
useProperties: false
tablePrefix: QRTZ_
misfireThreshold: 60000
clusterCheckinInterval: 5000
# 打开群集功能
isClustered: false
#连接池
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
boot:
admin:
context-path: /admin
@@ -112,7 +140,7 @@ logging:
logback:
rollingpolicy:
clean-history-on-start: false
file-name-pattern: ${logging.file.path}/rolling/orion-ops-rolling-%d{yyyy-MM-dd}.%i.gz
file-name-pattern: ${logging.file.path}/rolling/rolling-%d{yyyy-MM-dd}.%i.gz
max-history: 30
max-file-size: 16MB
total-size-cap: 0B
@@ -156,6 +184,7 @@ orion:
session-idle-timeout: 1800000
swagger:
# swagger 配置
author: lijiahang
title: orion-ops-pro 运维平台
description: 一站式运维服务平台
version: ${orion.version}