如何更新预定的石英作业?
How do update a scheduled quartz Job?
以下两个片段都出现此错误:
org.quartz.SchedulerException: Jobs added with no trigger must be
durable.
JobDetail job = scheduler.getJobDetail(jobKey(jobInfo));
job.getJobDataMap().put(JOB_CONTENT, objectMapper.writeValueAsString(jobInfo));
scheduler.addJob(job, true);
JobDetail job = JobBuilder
.newJob(MyJob.class)
.usingJobData(JOB_CONTENT, objectMapper.writeValueAsString(jobInfo))
.withIdentity(jobKey(jobInfo))
.build();
scheduler.addJob(job, true);
addJob()
用于添加没有附加触发器的作业:如果这是您想要的,只需添加对 storeDurably()
to the JobBuilder; if, as I can only guess, you want to otherwise update the job while retaining the old trigger, you will need to retrieve the existing trigger first, then, if the trigger will not need changes, scheduler.scheduleJob(newJob, oldTrigger)
; otherwise get a builder for it using TriggerBuilder.getTriggerBuilder();
的调用以构建副本,进行更改,并最终调用 scheduler.scheduleJob(newJob, newTrigger)
。
对于非持久性作业,您必须改用 scheduler.addJob(job, true, true)
和 3 个参数。第三个参数告诉 Quartz 存储作业(在 RAM 中)直到它被调度,即直到你为它添加一个触发器:
void addJob(JobDetail jobDetail,
boolean replace,
boolean storeNonDurableWhileAwaitingScheduling)
throws SchedulerException
With the storeNonDurableWhileAwaitingScheduling
parameter set to true
, a non-durable job can be stored. Once it is scheduled, it will resume normal non-durable behavior (i.e. be deleted once there are no remaining associated triggers).
除了作业特定的设置之外,如果您使用 Spring,您还应该确保您的 SchedulerFactoryBean
有 overwriteExistingjobs = true
。否则只有作业的初始 trigger/settings 会被持久化(如果你正在持久化它们)。
这将有助于绕过传统的作业更新方式。
Delete existing job first using scheduler.deleteJob(jobKey(name,group)).
Then Schedule new job using scheduler.scheduleJob(jobDetail,trigger,true).
用 try/catch(SchedulerEception se)
包围您的代码
注意:在石英属性中添加此 属性 :) spring.quartz.overwrite-existing-jobs = true 否则调度程序将添加新实例一份工作
以下两个片段都出现此错误:
org.quartz.SchedulerException: Jobs added with no trigger must be durable.
JobDetail job = scheduler.getJobDetail(jobKey(jobInfo));
job.getJobDataMap().put(JOB_CONTENT, objectMapper.writeValueAsString(jobInfo));
scheduler.addJob(job, true);
JobDetail job = JobBuilder
.newJob(MyJob.class)
.usingJobData(JOB_CONTENT, objectMapper.writeValueAsString(jobInfo))
.withIdentity(jobKey(jobInfo))
.build();
scheduler.addJob(job, true);
addJob()
用于添加没有附加触发器的作业:如果这是您想要的,只需添加对 storeDurably()
to the JobBuilder; if, as I can only guess, you want to otherwise update the job while retaining the old trigger, you will need to retrieve the existing trigger first, then, if the trigger will not need changes, scheduler.scheduleJob(newJob, oldTrigger)
; otherwise get a builder for it using TriggerBuilder.getTriggerBuilder();
的调用以构建副本,进行更改,并最终调用 scheduler.scheduleJob(newJob, newTrigger)
。
对于非持久性作业,您必须改用 scheduler.addJob(job, true, true)
和 3 个参数。第三个参数告诉 Quartz 存储作业(在 RAM 中)直到它被调度,即直到你为它添加一个触发器:
void addJob(JobDetail jobDetail, boolean replace, boolean storeNonDurableWhileAwaitingScheduling) throws SchedulerException
With the
storeNonDurableWhileAwaitingScheduling
parameter set totrue
, a non-durable job can be stored. Once it is scheduled, it will resume normal non-durable behavior (i.e. be deleted once there are no remaining associated triggers).
除了作业特定的设置之外,如果您使用 Spring,您还应该确保您的 SchedulerFactoryBean
有 overwriteExistingjobs = true
。否则只有作业的初始 trigger/settings 会被持久化(如果你正在持久化它们)。
这将有助于绕过传统的作业更新方式。
Delete existing job first using scheduler.deleteJob(jobKey(name,group)).
Then Schedule new job using scheduler.scheduleJob(jobDetail,trigger,true).
用 try/catch(SchedulerEception se)
包围您的代码注意:在石英属性中添加此 属性 :) spring.quartz.overwrite-existing-jobs = true 否则调度程序将添加新实例一份工作