Quartz Scheduler - trigger does not reference task

I use Quartz Scheduler in my application, and I get an exception: Trigger does not reference the given task ...

Looking at my code, I do not see where the problem is.

var schedFact = new StdSchedulerFactory(); scheduler = schedFact.GetScheduler(); IJobDetail dailyJob = JobBuilder.Create<PushElectricityPricesJob>() .WithIdentity("dailyJob", "group1") .Build(); ITrigger trigger1 = TriggerBuilder.Create() .WithIdentity("dailyJobTrigger", "group1") .StartNow() .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(3, 0)) .ForJob("dailyJob") .Build(); scheduler.ScheduleJob(dailyJob, trigger1); IJobDetail monthlyJob = JobBuilder.Create<PushContributionsJob>() .WithIdentity("monthlyJob", "group2") .Build(); ITrigger trigger2 = TriggerBuilder.Create() .WithIdentity("monthlyJobTrigger", "group2") .StartNow() .WithSchedule(CronScheduleBuilder.MonthlyOnDayAndHourAndMinute(1, 0, 0)) .ForJob("monthlyJob") .Build(); scheduler.ScheduleJob(monthlyJob, trigger2); scheduler.Start(); 

I found a lot of posts like this in StackOverflow, but on each of them I could notice an error or typo made by the developer. Here I just got stuck in ignorance ..

Any idea?

+5
source share
3 answers

Ok, found it!

The problem was due to the groups. The WithIdentity method can be called without specifying a group, just with a name.

So it will be:

 IJobDetail dailyJob = JobBuilder.Create<PushElectricityPricesJob>() .WithIdentity("dailyJob") .Build(); ITrigger trigger1 = TriggerBuilder.Create() .WithIdentity("dailyJobTrigger") .StartNow() .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(3, 0)) .ForJob("dailyJob") .Build(); 

And it works fine. Of course, you need to do the same for another job.

+8
source

remove .ForJob ("dailyJob")

or change to another

0
source

Use the same group as on jobDetail.withIdentity ("job01", "group1") on trigger.forJob ("job01", "group1")

The trigger should be informed about which group will work, for example:

  var schedFact = new StdSchedulerFactory(); scheduler = schedFact.GetScheduler(); IJobDetail dailyJob = JobBuilder.Create<PushElectricityPricesJob>() .WithIdentity("dailyJob", "group1") .Build(); ITrigger trigger1 = TriggerBuilder.Create() .WithIdentity("dailyJobTrigger", "group1") .StartNow() .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(3, 0)) .ForJob("dailyJob", "group1") .Build(); scheduler.ScheduleJob(dailyJob, trigger1); 

In addition, he will think that he is using the DEFAULT group and will not work.

0
source

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


All Articles