diff --git a/han-note-data-align/pom.xml b/han-note-data-align/pom.xml index 9431ba1..dbb99d5 100644 --- a/han-note-data-align/pom.xml +++ b/han-note-data-align/pom.xml @@ -77,6 +77,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + + + + com.xuxueli + xxl-job-core + diff --git a/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobConfig.java b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobConfig.java new file mode 100644 index 0000000..11417a1 --- /dev/null +++ b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobConfig.java @@ -0,0 +1,35 @@ +package com.hanserwei.hannote.data.align.config; + +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Slf4j +public class XxlJobConfig { + + @Resource + private XxlJobProperties xxlJobProperties; + + /** + * 初始化执行器 + * + * @return xxlJobSpringExecutor + */ + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + log.info(">>>>>>>>>>> xxl-job config init."); + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses()); + xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppName()); + xxlJobSpringExecutor.setIp(xxlJobProperties.getIp()); + xxlJobSpringExecutor.setPort(xxlJobProperties.getPort()); + xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken()); + xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath()); + xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays()); + return xxlJobSpringExecutor; + } + +} \ No newline at end of file diff --git a/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobProperties.java b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobProperties.java new file mode 100644 index 0000000..3c4e348 --- /dev/null +++ b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/config/XxlJobProperties.java @@ -0,0 +1,27 @@ +package com.hanserwei.hannote.data.align.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@ConfigurationProperties(prefix = XxlJobProperties.PREFIX) +@Component +@Data +public class XxlJobProperties { + + public static final String PREFIX = "xxl.job"; + + private String adminAddresses; + + private String accessToken; + + private String appName; + + private String ip; + + private int port; + + private String logPath; + + private int logRetentionDays = 30; +} \ No newline at end of file diff --git a/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/job/CreateTableXxlJob.java b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/job/CreateTableXxlJob.java new file mode 100644 index 0000000..f8f1f56 --- /dev/null +++ b/han-note-data-align/src/main/java/com/hanserwei/hannote/data/align/job/CreateTableXxlJob.java @@ -0,0 +1,20 @@ +package com.hanserwei.hannote.data.align.job; + +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import org.springframework.stereotype.Component; + +@Component +public class CreateTableXxlJob { + + /** + * 1、简单任务示例(Bean模式) + */ + @XxlJob("createTableJobHandler") + public void createTableJobHandler() throws Exception { + XxlJobHelper.log("## 开始初始化明日增量数据表..."); + + // TODO + } + +} \ No newline at end of file