英文:
How to find out if the Quartz Job is paused
问题
在我的Spring Boot应用程序中,我使用了Quartz的org.quartz.Scheduler
来调度一个任务:
final JobDetail job = JobBuilder.newJob().ofType(ReportSendingJob.class)
.storeDurably()
.withIdentity("myJob")
.build();
final CronTrigger trigger = TriggerBuilder.newTrigger().forJob(job)
.withIdentity(scheduleName)
.withSchedule(CronScheduleBuilder.cronSchedule(schedule.getCronExpression()).withMisfireHandlingInstructionDoNothing())
.build();
scheduler.scheduleJob(job, trigger);
然后我将其暂停:
scheduler.pauseJob(new JobKey("myJob"));
如何获取此作业的状态以查看是否已暂停?
英文:
In my Spring Boot application I used Quartz org.quartz.Scheduler
to schedule a job:
final JobDetail job = JobBuilder.newJob().ofType(ReportSendingJob.class)
.storeDurably()
.withIdentity("myJob")
.build();
final CronTrigger trigger = TriggerBuilder.newTrigger().forJob(job)
.withIdentity(scheduleName)
.withSchedule(CronScheduleBuilder.cronSchedule(schedule.getCronExpression()).withMisfireHandlingInstructionDoNothing())
.build();
scheduler.scheduleJob(job, trigger);
then I paused it:
scheduler.pauseJob(new JobKey("myJob"));
How can I get the status of this job to see if it is paused or not?
答案1
得分: 1
pauseJob
方法的文档说明如下:
> 暂停具有给定键的 JobDetail - 通过暂停其所有当前触发器。
因此,您可以通过检查所有触发器是否已暂停来确定作业是否已暂停:
List<Trigger> triggers = scheduler.getTriggersOfJob(JobKey.jobKey("myJob"))
boolean paused = triggers
.stream()
.allMatch(trigger ->
scheduler.getTriggerState(trigger.key) == PAUSED
)
英文:
Documentation of pauseJob
method says
> Pause the JobDetail with the given key - by pausing all of its current Triggers.
So you could check if job is paused by checking if all triggers are paused:
List<Trigger> triggers = scheduler.getTriggersOfJob(JobKey.jobKey("myJob"))
boolean paused = triggers
.stream()
.allMatch( trigger ->
scheduler.getTriggerState(trigger.key) == PAUSED
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论