Marian Ene
Marian Ene

Reputation: 665

The job does not exist (Quartz .NET)

I'm currently using Quartz .NET version 1.0.3 in a project. For some reason I can't upgrade it to the newest version.

These are the methods that I use:

ScheduleUnreserveCarJob

Trigger trigger = CreateTrigger(typeof(UnreserveCarJob), lotId.ToString(), startTimeUtc);

trigger.JobDataMap.PutAsString(JobDataMapKeys.LotId, lotId);

scheduler.ScheduleJob(trigger);

UnreserveCarJob

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods")]
    protected override void ExecuteJob(JobExecutionContext context)
    {
        using (IAuctionProcessClient auctionProcessClient = new AuctionServiceClient())
        {
            var request = LotGetRequest(context.MergedJobDataMap);

            auctionProcessClient.LotGet(request);
        }
    }

    private static LotGetRequest LotGetRequest(JobDataMap jobDataMap)
    {
        return new LotGetRequest { Lot = jobDataMap.GetInt(JobDataMapKeys.LotId) };
    }

CreateTrigger

var jobTypeName = jobType.Name;

        return new SimpleTrigger
        {
            Group = jobTypeName,
            JobName = jobTypeName,
            MisfireInstruction = MisfireInstruction.SimpleTrigger.FireNow,
            Name = name,
            StartTimeUtc = startTimeUtc
        };

When I want to execute ScheduleJob from ScheduleUnreserveCarJob, I always get the error The job DEFAULT.UnreserveCarJob referenced by the trigger does not exist.

The triggers are saved in the DB, so in the QRTZ_JOB_LISTENERS and QRTZ_JOB_DETAILS I have a row with JOB_NAME UnreserveCarJob and JOB_GROUP DEFAULT.

What could be the reason of this problem?

EDIT: I've insert the details for the QRTZ_JOB tables manually, so the trigger can go to the QRTZ_TRIGGERS table (did that because of the FKs). My guess is that the Quartz.dll is not inserting any rows in the DB. I still don't know why.

EDIT 2: I've tracked the issue with SQL Server Profiler and the problem is at scheduler.ScheduleJob(trigger);. When running this line, an INSERT must be made on QRTZ_TRIGGERS and QRTZ_SIMPLE_TRIGGERS. Unfortunately, I get The job referenced by the trigger does not exist. For some reason, quartz.dll is not inserting in the tables.

Upvotes: 3

Views: 2953

Answers (1)

Duy Dang
Duy Dang

Reputation: 21

When a trigger is fired, the Quartz.NET finds a JobDetail instance by its identity specified by the trigger. The identity is a pair value of job name and job group. If no instance is found, the error The job DEFAULT.UnreserveCarJob referenced by the trigger does not exist will be returned. There are two possible cases: no job detail is created yet or the job detail is created with the wrong job name or job group. So, your case sounds like the first one according to your EDIT notes.

If you want to schedule a new trigger for a new job, the correct API should be scheduler.ScheduleJob(jobDetail, trigger); and jobDetail is the instance of IJobDetail class that can be created through JobBuilder. Note: the identity of the job detail must be identical to the one you specify in the trigger.

Side note: the source code of CreateTrigger might be wrong because it sets job group by job name.

    var jobTypeName = jobType.Name;

    return new SimpleTrigger
    {
        Group = jobTypeName, <-- WRONG
        JobName = jobTypeName,

Upvotes: 1

Related Questions