Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz.NET Rescheduling job with new trigger set

I have a Quartz job which is scheduled with a collection of triggers and it has 3 to 5 minutes of execution time. But at any moment in the future(it may be a week later or a couple of minutes later) I may need to reschedule it with a new trigger set. There will be some additions or deletions on trigger set.

How can I reschedule the job with new trigger set? The trick here is, I want to be sure that no instance of the job is alive at that moment, so I can reschedule my job reliably. Thanks for any help...

like image 406
ayk Avatar asked May 02 '13 09:05

ayk


1 Answers

As I remember it, you can do:

List<JobExecutionContext> context = scheduler.GetCurrentlyExecutingJobs()

Iterate the list and call GetJobInstance() (or something similar) to find the job the context was created for, then check if it's the job you're interested in. If not, you can reschedule using the same trigger. Try something like this:

Trigger trigger = Global.scheduler.GetTrigger("testTrigger","triggerGroup");

trigger.set(); 

Global.scheduler.RescheduleJob(trigger.JobName, trigger.JobGroup, trigger);
like image 109
Nick Patsaris Avatar answered Oct 03 '22 18:10

Nick Patsaris