{"record":{"id":"f2f9b92d052d1bd2","repo":"elunez/eladmin","slug":"error-f2f9b9","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":160,"sourceCode":"    /**\n     * 立即执行job\n     * @param quartzJob /\n     */\n    public void runJobNow(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            JobDataMap dataMap = new JobDataMap();\n            dataMap.put(QuartzJob.JOB_KEY, quartzJob);\n            JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());\n            scheduler.triggerJob(jobKey,dataMap);\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 pauseJob(QuartzJob quartzJob){\n        try {\n            JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());\n            scheduler.pauseJob(jobKey);\n        } catch (Exception e){\n            log.error(\"定时任务暂停失败\", e);\n            throw new BadRequestException(\"定时任务暂停失败\");\n        }\n    }\n}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java#L142-L178","documentation":"QuartzManage.runJobNow implements 'execute immediately': it fetches the trigger (creating the job via addJob if the trigger is null), then scheduler.triggerJob(jobKey, dataMap) to fire it once outside the cron schedule. Any exception is logged and rethrown as BadRequestException '定时任务执行失败'. This does not affect the job's schedule.","triggerScenarios":"Clicking 执行 on a quartz job in the UI (runJobNow endpoint) when the scheduler throws: missing job detail after a failed lazy addJob, scheduler standby, or the job class cannot be instantiated by Quartz at trigger time.","commonSituations":"JobDetail missing because the trigger existed but the job did not (partial state); target bean removed from Spring context so ExecutionException occurs; scheduler paused globally; concurrent-run policy rejecting the manual fire in some store states.","solutions":["Read the logged stack trace to find whether addJob or triggerJob failed and why.","Recreate the job (delete + add) to rebuild both job detail and trigger atomically.","Verify the job's bean still exists as a @Service bean (the runtime instantiation uses the Spring context via the job factory)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure job detail exists before manual fire\nJobKey jk = JobKey.jobKey(\"JOB_NAME\" + job.getId());\nif (!scheduler.checkExists(jk)) quartzManage.addJob(job); // rebuilds detail+trigger\nscheduler.triggerJob(jk, new JobDataMap(Map.of(QuartzJob.JOB_KEY, job)));","typeGuard":null,"tryCatchPattern":"try { quartzJobService.execution(job); } catch (BadRequestException e) { if (\"定时任务执行失败\".equals(e.getMessage())) { log.error(\"manual fire failed\", e); return fail(\"执行失败：请检查任务Bean与调度器状态（日志有详细堆栈）\"); } throw e; }","preventionTips":["Check the target bean still exists as @Service before manual execution.","Smoke-test jobs with 执行 immediately after creation to catch instantiation problems early.","Correlate the API failure with the server stack trace — the message alone says nothing."],"tags":["quartz","scheduler","execution","diagnostics"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}