Retrieving All Active Jobs from Quartz.NET Scheduler

How can I get all the active jobs scheduled in the Quartz.net scheduler? I tried GetCurrentlyExecutingJobs (), but it always returns 0.

+6
source share
1 answer

This method does not seem to work.
The only solution I found was to complete all the tasks:

var groups = sched.JobGroupNames; for (int i = 0; i < groups.Length; i++) { string[] names = sched.GetJobNames(groups[i]); for (int j = 0; j < names.Length; j++) { var currentJob = sched.GetJobDetail(names[j], groups[i]); } } 

When a job is found, it means that it is still active. If you set your work to be durable , however, it will never be deleted if there is no corresponding trigger.
In this situation, this code works better:

 var groups = sched.JobGroupNames; for (int i = 0; i < groups.Length; i++) { string[] names = sched.GetJobNames(groups[i]); for (int j = 0; j < names.Length; j++) { var currentJob = sched.GetJobDetail(names[j], groups[i]); if (sched.GetTriggersOfJob(names[j], groups[i]).Count() > 0) { // still scheduled. } } } 

UPDATE

I did some debugging to find out what happens with GetCurrentlyExecutingJobs() .
It actually returns the job in progress, but the items are removed from the collection as soon as the job is completed.
You can test 2 functions JobToBeExecuted and JobWasExecuted in the QuartzScheduler class.

+8
source

Source: https://habr.com/ru/post/892475/


All Articles