定时任务测试

This commit is contained in:
yang
2024-11-30 12:08:11 +08:00
parent 423b658e04
commit 4205912db5
5 changed files with 70 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
package com.xboe;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class XxlJobConfig {
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.executor.appname}")
private String appName;
@Value("${xxl.job.executor.ip}")
private String ip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
// 创建 XxlJobSpringExecutor 执行器
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appName);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
// 返回
return xxlJobSpringExecutor;
}
}

View File

@@ -1,6 +1,7 @@
package com.xboe.module.boecase.api;
import com.xboe.module.boecase.service.ICasesService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -16,6 +17,7 @@ public class CaseScheduledTasks {
* 每月的第一天的1:00执行
*/
// @Scheduled(cron = "0 0 1 1 * ?")
@XxlJob("refreshViewsRankOfMajor")
public void refreshViewsRankOfMajor() {
casesService.refreshViewsRankOfMajor();
}
@@ -23,7 +25,8 @@ public class CaseScheduledTasks {
/**
* 季初第一天两点执行cron表达式设置为每个季度的第一个月的第一天的特定时间。每个季度的第一个月是1月、4月、7月和10月
*/
@Scheduled(cron = "0 0 2 1 1,4,7,10 ?")
// @Scheduled(cron = "0 0 2 1 1,4,7,10 ?")
@XxlJob("refreshLastQuarterStatistics")
public void refreshLastQuarterStatistics() {
casesService.refreshLastQuarterStatistics();
}