.netquartz-scheduler

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?


Solution

  • 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.