Quartz Scheduler - 忽略失败的工作 - withMisfireHandlingInstructionDoNothing() 不工作
Quartz Scheduler - Ignore misfired job - withMisfireHandlingInstructionDoNothing() not working
我想忽略任何失败的作业(比如服务中断时),等到下一个时间表。
为此,我在下面进行了尝试:
TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)
.withMisfireHandlingInstructionDoNothing())
.withPriority(jobPriority).build();
此作业每周二触发。比如说在某个星期二,服务中断了,但在星期五出现了。然后作业应该在下周二触发,而不是在服务启动时触发。
但是上面的代码不起作用。服务启动后立即触发作业。
注意:我手动转发时间来测试这个(以防万一)
我想我明白了。
要让MisfireHandlingInstruction生效,延迟应该大于
设置的值
org.quartz.jobStore.misfireThreshold = 600000
否则石英永远不会将触发器视为失火。所以misfire指令不会生效
来自here
Before I dive into the details, there is yet another configuration option that should be described. It is org.quartz.jobStore.misfireThreshold (in milliseconds), defaulting to 60000 (a minute). It defines how late the trigger should be to be considered misfired. With default setup if trigger was suppose to be fired 30 seconds ago, Quartz will happily just run it. Such delay is not considered misfiring. However if the trigger is discovered 61 seconds after the scheduled time - the special misfire handler thread takes care of it, obeying the misfire instruction. For test purposes we will set this parameter to 1000 (1 second) so that we can test misfiring quickly.
我想忽略任何失败的作业(比如服务中断时),等到下一个时间表。
为此,我在下面进行了尝试:
TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)
.withMisfireHandlingInstructionDoNothing())
.withPriority(jobPriority).build();
此作业每周二触发。比如说在某个星期二,服务中断了,但在星期五出现了。然后作业应该在下周二触发,而不是在服务启动时触发。
但是上面的代码不起作用。服务启动后立即触发作业。
注意:我手动转发时间来测试这个(以防万一)
我想我明白了。
要让MisfireHandlingInstruction生效,延迟应该大于
设置的值org.quartz.jobStore.misfireThreshold = 600000
否则石英永远不会将触发器视为失火。所以misfire指令不会生效
来自here
Before I dive into the details, there is yet another configuration option that should be described. It is org.quartz.jobStore.misfireThreshold (in milliseconds), defaulting to 60000 (a minute). It defines how late the trigger should be to be considered misfired. With default setup if trigger was suppose to be fired 30 seconds ago, Quartz will happily just run it. Such delay is not considered misfiring. However if the trigger is discovered 61 seconds after the scheduled time - the special misfire handler thread takes care of it, obeying the misfire instruction. For test purposes we will set this parameter to 1000 (1 second) so that we can test misfiring quickly.