定时任务日志

This commit is contained in:
Jack 2025-09-25 12:03:37 +08:00
parent db7d63f1e8
commit 51acebb152

View File

@ -58,19 +58,15 @@ public class QuartzServiceImpl implements QuartzService {
throw new ApiException(I18nUtil._("任务实现类名称不能为空!"));
}
// 2. 加载任务类
Class<Job> clazz;
try {
// 2. 加载任务类
Class<Job> clazz;
String fullClassName = PATH_PREFIX + cName;
logger.debug("[Quartz] 尝试加载任务类: {}", fullClassName);
clazz = (Class<Job>) Class.forName(fullClassName);
logger.debug("[Quartz] 成功加载任务类: {}", fullClassName);
} catch (ClassNotFoundException e) {
logger.error("[Quartz] 定时任务脚本不存在!类名: {}{}", PATH_PREFIX, cName, e);
throw new ApiException(I18nUtil._("定时任务脚本不存在!类名: " + PATH_PREFIX + cName), e);
}
try {
// 3. 构建任务详情和触发器
JobKey jobKey = new JobKey(jName, jGroup);
JobDetail jobDetail = JobBuilder.newJob(clazz)
@ -86,6 +82,9 @@ public class QuartzServiceImpl implements QuartzService {
logger.debug("[Quartz] 构建任务详情和触发器完成: jobKey={}, triggerKey={}", jobKey, triggerKey);
// 打印最终执行的 cron 表达式
logger.info("[Quartz] 定时任务最终执行表达式: {}", trigger.getCronExpression());
// 4. 检查任务是否已存在
if (scheduler.checkExists(jobKey)) {
logger.info("[Quartz] 任务已存在,先删除旧任务: jobKey={}", jobKey);
@ -107,6 +106,9 @@ public class QuartzServiceImpl implements QuartzService {
logger.error("[Quartz] 添加定时任务失败!任务名称={}, 任务组={}, 触发器名称={}, 触发器组={}",
jName, jGroup, tName, tGroup, e);
throw new ApiException(I18nUtil._("添加定时任务失败!"), e);
} catch (ClassNotFoundException e) {
logger.error("[Quartz] 定时任务脚本不存在!类名: {}{}", PATH_PREFIX, cName, e);
throw new ApiException(I18nUtil._("定时任务脚本不存在!类名: " + PATH_PREFIX + cName), e);
} catch (Exception e) {
logger.error("[Quartz] 添加定时任务时发生未知异常!任务名称={}, 任务组={}, 触发器名称={}, 触发器组={}",
jName, jGroup, tName, tGroup, e);