feat(job): 添加测试的xxljob
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.zt.plat.module.base.job;
|
||||
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import com.zt.plat.framework.tenant.core.job.TenantJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 测试定时任务
|
||||
*
|
||||
* @author base
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TestJob {
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
* 简单测试任务
|
||||
*/
|
||||
@XxlJob("testSimpleJob")
|
||||
@TenantJob
|
||||
public void testSimpleJob() {
|
||||
String currentTime = LocalDateTime.now().format(FORMATTER);
|
||||
log.info("[testSimpleJob][开始执行] 当前时间: {}", currentTime);
|
||||
|
||||
try {
|
||||
// 模拟业务处理
|
||||
Thread.sleep(2000);
|
||||
log.info("[testSimpleJob][执行成功] 任务已完成");
|
||||
} catch (Exception e) {
|
||||
log.error("[testSimpleJob][执行失败] 错误信息: {}", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 带参数的测试任务
|
||||
*/
|
||||
@XxlJob("testParamJob")
|
||||
@TenantJob
|
||||
public void testParamJob() {
|
||||
String currentTime = LocalDateTime.now().format(FORMATTER);
|
||||
log.info("[testParamJob][开始执行] 当前时间: {}", currentTime);
|
||||
|
||||
try {
|
||||
// 模拟带参数的业务处理
|
||||
log.info("[testParamJob][处理中] 正在处理业务逻辑...");
|
||||
Thread.sleep(1000);
|
||||
log.info("[testParamJob][执行成功] 任务已完成");
|
||||
} catch (Exception e) {
|
||||
log.error("[testParamJob][执行失败] 错误信息: {}", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user