I'm using the Quartz Scheduler in my application and I get the exception: Trigger does not reference the given job...
Looking at my code I can't seem to see where the problem could be.
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 did found a lot of posts like this one on StackOverflow but on each of them I could spot the mistake or typo that the dev made. Here I'm just stuck clueless..
Any idea?
The actual number of jobs that can be running at any moment in time is limited by the size of the thread pool. If there are five threads in the pool, no more than five jobs can run at a time.
Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.
qrtz_triggers is where general information of a trigger is saved. qrtz_simple_triggers, qrtz_simprop_triggers, qrtz_crons_triggers, qrtz_blob_triggers have a foreign key relation to qrtz_triggers which save those specific details. Ex. Cron has cron expression which is unique to it.
Ok found it!
Problem was because of the groups. The WithIdentity method can be called without specifying the group, just with the name.
So it becomes:
IJobDetail dailyJob = JobBuilder.Create<PushElectricityPricesJob>()
.WithIdentity("dailyJob")
.Build();
ITrigger trigger1 = TriggerBuilder.Create()
.WithIdentity("dailyJobTrigger")
.StartNow()
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(3, 0))
.ForJob("dailyJob")
.Build();
And that seems to work fine. Of course you need to do the same for the other job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With