{"record":{"id":"7b246f2f43c734ba","repo":"elunez/eladmin","slug":"error-7b246f","errorCode":null,"errorMessage":"删除定时任务失败","messagePattern":"删除定时任务失败","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java","lineNumber":118,"sourceCode":"        } catch (Exception e){\n            log.error(\"更新定时任务失败\", e);\n            throw new BadRequestException(\"更新定时任务失败\");\n        }\n\n    }\n\n    /**\n     * 删除一个job\n     * @param quartzJob /\n     */\n    public void deleteJob(QuartzJob quartzJob){\n        try {\n            JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());\n            scheduler.pauseJob(jobKey);\n            scheduler.deleteJob(jobKey);\n        } catch (Exception e){\n            log.error(\"删除定时任务失败\", e);\n            throw new BadRequestException(\"删除定时任务失败\");\n        }\n    }\n\n    /**\n     * 恢复一个job\n     * @param quartzJob /\n     */\n    public void resumeJob(QuartzJob quartzJob){\n        try {\n            TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());\n            CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);\n            // 如果不存在则创建一个定时任务\n            if(trigger == null) {\n                addJob(quartzJob);\n            }\n            JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());\n            scheduler.resumeJob(jobKey);\n        } catch (Exception e){","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java#L100-L136","documentation":"QuartzManage.deleteJob does scheduler.pauseJob(jobKey) then scheduler.deleteJob(jobKey) inside a try/catch; any SchedulerException is logged and rethrown as BadRequestException '删除定时任务失败'. The calling service delete() is transactional, so the quartz_job DB row survives if the scheduler delete fails.","triggerScenarios":"DELETE /api/quartz/jobs when the scheduler cannot process the delete: scheduler down/standby, JDBC job store unreachable, or job key in an inconsistent state. Deleting jobs whose scheduler entry is already gone can also surface errors depending on store implementation.","commonSituations":"Quartz JDBC store pointing at a database that is down; clustered scheduler node split; jobs deleted directly in QRTZ_ tables leaving orphaned keys; scheduler shut down during app shutdown race.","solutions":["Inspect the stack trace after the '删除定时任务失败' log line to identify the SchedulerException cause.","Restore scheduler/database availability and retry the delete — it is idempotent from the UI.","If DB and scheduler state have diverged, manually reconcile (remove orphaned QRTZ_ rows or quartz_job rows) so both sides agree."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check the job exists in the scheduler before deleting\nJobKey jk = JobKey.jobKey(\"JOB_NAME\" + id);\nif (scheduler.checkExists(jk)) { scheduler.pauseJob(jk); scheduler.deleteJob(jk); }\n// then delete the DB row — avoids throwing on already-missing keys","typeGuard":null,"tryCatchPattern":"try { quartzJobService.delete(ids); } catch (BadRequestException e) { if (\"删除定时任务失败\".equals(e.getMessage())) { log.error(\"scheduler delete failed\", e); return fail(\"删除失败，详见服务端日志\"); } throw e; }","preventionTips":["Use checkExists before pause/delete for idempotent deletes.","Keep QRTZ_ tables and quartz_job rows in sync during backups/restores.","Never delete scheduler rows manually via SQL without also cleaning quartz_job."],"tags":["quartz","scheduler","delete","state-mismatch"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}