Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz Scheduler - trigger does not reference given job

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?

like image 275
Georges Legros Avatar asked Sep 17 '14 16:09

Georges Legros


People also ask

How many jobs can Quartz handle?

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.

How does Quartz Scheduler work internally?

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.

What is Qrtz_triggers?

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.


1 Answers

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.

like image 184
Georges Legros Avatar answered Nov 15 '22 10:11

Georges Legros