elunez/eladmin · error · BadRequestException
恢复定时任务失败
Error message
恢复定时任务失败
What it means
QuartzManage.resumeJob looks up the trigger by JOB_NAME+id; if absent it calls addJob(quartzJob) first, then scheduler.resumeJob(jobKey). Any exception in that sequence (including failures inside the nested addJob) is logged and rethrown as BadRequestException '恢复定时任务失败'. Used when un-pausing a job (updateIsPause).
Source
Thrown at eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java:138
}
/**
* 恢复一个job
* @param quartzJob /
*/
public void resumeJob(QuartzJob quartzJob){
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null) {
addJob(quartzJob);
}
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
scheduler.resumeJob(jobKey);
} catch (Exception e){
log.error("恢复定时任务失败", e);
throw new BadRequestException("恢复定时任务失败");
}
}
/**
* 立即执行job
* @param quartzJob /
*/
public void runJobNow(QuartzJob quartzJob){
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null) {
addJob(quartzJob);
}
JobDataMap dataMap = new JobDataMap();
dataMap.put(QuartzJob.JOB_KEY, quartzJob);
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());View on GitHub (pinned to 55fbf70595)
Solutions
- Check the log for the underlying exception logged just before the BadRequestException is raised.
- If the trigger genuinely vanished, delete and recreate the job so addJob runs cleanly in the create path.
- Ensure scheduler health (datasource for JDBC store, auto-startup enabled) before resuming jobs.
Defensive patterns
Strategy: try-catch
Validate before calling
// verify trigger presence; recreate proactively rather than relying on the lazy addJob
TriggerKey tk = TriggerKey.triggerKey("JOB_NAME" + job.getId());
if (scheduler.getTrigger(tk) == null) quartzManage.addJob(job);
scheduler.resumeJob(JobKey.jobKey("JOB_NAME" + job.getId())); Try / catch
try { quartzJobService.updateIsPause(job); } catch (BadRequestException e) { if ("恢复定时任务失败".equals(e.getMessage())) { log.error("resume failed", e); return fail("请删除后重新创建该任务以重建调度状态"); } throw e; } Prevention
- Recreate jobs whose scheduler state has drifted instead of fighting resume failures.
- Monitor for quartz_job rows without live triggers after every restart.
- Avoid switching a deployment between RAM and JDBC job stores.
When it happens
Trigger: Calling the resume/执行 endpoint for a job whose trigger AND job detail are missing from the scheduler (the lazy addJob must succeed for resume to proceed), or when the scheduler itself is in an error state. Nested addJob failures propagate the same message.
Common situations: Job row exists in DB but scheduler store was reset (restart with RAMJobStore after a DB restore); scheduler misconfiguration surfacing here instead of at create time because addJob is lazily invoked.
Related errors
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/309e6c080da890cc.
Report an issue: GitHub.