我正在运行一个Spring Boot应用程序(版本:2.3.2.RELEASE)并使用Quartz调度作业。 我有以下方法来构建“工作详细信息”:
private JobDetail buildJobDetail(JobKey key, Long bookingId, String jobDescription,
Class<? extends QuartzJobBean> jobClass, Map<String, Object> customDataMap) {
final String description = String.format(jobDescription, bookingId);
JobDataMap jobDataMap = JobUtils.buildDataMap(customDataMap);
return JobBuilder.newJob(jobClass)
.withIdentity(key)
.withDescription(description)
.usingJobData(jobDataMap)
.storeDurably()
.build();
}
以及以下构建作业触发器的方法:
private Trigger buildTrigger(JobKey key, Long bookingId, String jobDescription,
String triggerGroupName, Map<String, Object> customDataMap) {
final String triggerDescription = String.format(jobDescription, bookingId);
Date executionDate = (Date) customDataMap.get(EXECUTION_DATE);
return TriggerBuilder.newTrigger()
.forJob(key)
.withIdentity(key.getName(), triggerGroupName)
.withDescription(triggerDescription)
.startAt(executionDate)
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withMisfireHandlingInstructionFireNow())
.build();
}
认为我丢失了一些东西,但是当我计划一个作业(将其保存到数据库中)并在执行日期之前拆除应用程序时,在应用程序再次启动时不会执行该作业。我知道这一定是由于某些失火选项配置引起的,但我不知道是否有此功能。
我认为,在应用程序启动时,我可以启动调度程序并“查询数据库”并检查状态并将其重新调度(到now())。如果还有另一个更短的选项,并且有人知道,请发布它们...
1st。编辑 我删除了de initialize schema选项,仅此而已...是我的错误...感谢所有人