0

I have a scheduler task that runs regularly (once a minute). I run this task using the following snippet:

Scheduler = await StdSchedulerFactory.GetDefaultScheduler().ConfigureAwait(false);
await Scheduler.Start().ConfigureAwait(false);
JobDetail = JobBuilder.Create<SchedulerJob>().Build();
Trigger = TriggerBuilder.Create().StartNow().WithPriority(1).WithCronSchedule(cronExpression).Build();
await Scheduler.ScheduleJob(JobDetail, Trigger).ConfigureAwait(false);

What I want/need to do now is to schedule a second separate task that is not concurrent. This means the second, new task has priority, always running when both are called simultanuously and the first task either waiting or not executing.

Both Classes (SchedulerJob and the new Class) are marked as [DisallowConcurrentExecution], but they still both run at the same time.

I also tried two alternatives with JobDataMap:

  • Reuse JobDetail, use with different JobDataMap -> Problem is that scheduler does not allow scheduling the same JobDetail again with a different map.
  • Make new JobDetail with the same class, with different JobDataMap, on the same class -> Problem is that they are still executed at the same time, [DisallowConcurrentExecution] has no effect

Is there a built-in way with Quartz to have two separate JobDetails/Job Classes be non-concurrent? I wanted to avoid having to implement non-concurrency checks manually.

walen
  • 7,103
  • 2
  • 37
  • 58
private_meta
  • 561
  • 4
  • 19
  • `Trigger Priorities` should be your solution...see this for example https://stackoverflow.com/questions/6941523/how-can-i-set-priorities-to-quartz-trigger – yishaiz Oct 07 '18 at 17:43
  • Priorities don't prevent parallel execution of two scheduled tasks, they only make sure which task is started first. While I already need to use priorities, I wanted a built-in solution on how to ensure non-concurrency after priority is ensured. – private_meta Oct 08 '18 at 08:18
  • I see. I don't know of built-in Quartz capability for that. 2 possible ways to solve the issue: 1. use Quartz job\trigger listeners to implement non-concurrency checks. See example here https://stackoverflow.com/questions/12957019/quartz-jobs-disallow-concurrent-execution-group-wide. – yishaiz Oct 10 '18 at 06:06
  • 2. use trigger's data map and not the job data map. See example here https://stackoverflow.com/questions/42536771/can-you-run-two-different-quartz-job-instances-sequentially – yishaiz Oct 10 '18 at 06:08

0 Answers0