初始化项目提交,并添加 flowable 7 的 dm 兼容
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package cn.iocoder.yudao.framework.quartz.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* XXL-Job 配置类
|
||||
*/
|
||||
@ConfigurationProperties("xxl.job")
|
||||
@Validated
|
||||
@Data
|
||||
public class XxlJobProperties {
|
||||
|
||||
/**
|
||||
* 是否开启,默认为 true 关闭
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
private String accessToken;
|
||||
/**
|
||||
* 控制器配置
|
||||
*/
|
||||
@NotNull(message = "控制器配置不能为空")
|
||||
private AdminProperties admin;
|
||||
/**
|
||||
* 执行器配置
|
||||
*/
|
||||
@NotNull(message = "执行器配置不能为空")
|
||||
private ExecutorProperties executor;
|
||||
|
||||
/**
|
||||
* XXL-Job 调度器配置类
|
||||
*/
|
||||
@Data
|
||||
@Valid
|
||||
public static class AdminProperties {
|
||||
|
||||
/**
|
||||
* 调度器地址
|
||||
*/
|
||||
@NotEmpty(message = "调度器地址不能为空")
|
||||
private String addresses;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* XXL-Job 执行器配置类
|
||||
*/
|
||||
@Data
|
||||
@Valid
|
||||
public static class ExecutorProperties {
|
||||
|
||||
/**
|
||||
* 默认端口
|
||||
*
|
||||
* 这里使用 -1 表示随机
|
||||
*/
|
||||
private static final Integer PORT_DEFAULT = -1;
|
||||
|
||||
/**
|
||||
* 默认日志保留天数
|
||||
*
|
||||
* 如果想永久保留,则设置为 -1
|
||||
*/
|
||||
private static final Integer LOG_RETENTION_DAYS_DEFAULT = 30;
|
||||
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
@NotEmpty(message = "应用名不能为空")
|
||||
private String appName;
|
||||
/**
|
||||
* 执行器的 IP
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 执行器的 Port
|
||||
*/
|
||||
private Integer port = PORT_DEFAULT;
|
||||
/**
|
||||
* 日志地址
|
||||
*/
|
||||
@NotEmpty(message = "日志地址不能为空")
|
||||
private String logPath;
|
||||
/**
|
||||
* 日志保留天数
|
||||
*/
|
||||
private Integer logRetentionDays = LOG_RETENTION_DAYS_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.framework.quartz.config;
|
||||
|
||||
import com.alibaba.ttl.TtlRunnable;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/**
|
||||
* 异步任务 Configuration
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableAsync
|
||||
public class YudaoAsyncAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public BeanPostProcessor threadPoolTaskExecutorBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (!(bean instanceof ThreadPoolTaskExecutor)) {
|
||||
return bean;
|
||||
}
|
||||
// 修改提交的任务,接入 TransmittableThreadLocal
|
||||
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
|
||||
executor.setTaskDecorator(TtlRunnable::get);
|
||||
return executor;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.framework.quartz.config;
|
||||
|
||||
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* XXL-Job 自动配置类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ConditionalOnClass(XxlJobSpringExecutor.class)
|
||||
@ConditionalOnProperty(prefix = "xxl.job", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@EnableConfigurationProperties({XxlJobProperties.class})
|
||||
@EnableScheduling // 开启 Spring 自带的定时任务
|
||||
@Slf4j
|
||||
public class YudaoXxlJobAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public XxlJobExecutor xxlJobExecutor(XxlJobProperties properties) {
|
||||
log.info("[xxlJobExecutor][初始化 XXL-Job 执行器的配置]");
|
||||
XxlJobProperties.AdminProperties admin = properties.getAdmin();
|
||||
XxlJobProperties.ExecutorProperties executor = properties.getExecutor();
|
||||
|
||||
// 初始化执行器
|
||||
XxlJobExecutor xxlJobExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobExecutor.setIp(executor.getIp());
|
||||
xxlJobExecutor.setPort(executor.getPort());
|
||||
xxlJobExecutor.setAppname(executor.getAppName());
|
||||
xxlJobExecutor.setLogPath(executor.getLogPath());
|
||||
xxlJobExecutor.setLogRetentionDays(executor.getLogRetentionDays());
|
||||
xxlJobExecutor.setAdminAddresses(admin.getAddresses());
|
||||
xxlJobExecutor.setAccessToken(properties.getAccessToken());
|
||||
return xxlJobExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* 1. 定时任务,基于 XXL-Job 实现。
|
||||
* 2. 异步任务,采用 Spring Async 异步执行。
|
||||
*/
|
||||
package cn.iocoder.yudao.framework.quartz;
|
||||
@@ -0,0 +1,2 @@
|
||||
cn.iocoder.yudao.framework.quartz.config.YudaoXxlJobAutoConfiguration
|
||||
cn.iocoder.yudao.framework.quartz.config.YudaoAsyncAutoConfiguration
|
||||
Reference in New Issue
Block a user