Question

I'm working in C# using Quartz.NET and am having problems setting the misfire instruction on a CronTrigger. I'm running an SQL backend with the Quartz DB installed. I have the following code which works fine for creating a job and running a scheduler.

IScheduler _scheduler;
IJobDetail job;
ISchedulerFactory sFactory;
ICronTrigger trig;

sFactory = new StdSchedulerFactory();

_scheduler = sFactory.GetScheduler();
_scheduler.Start();

job = JobBuilder.Create<Test>().WithIdentity("testJob", "testGroup").Build();
trig = (ICronTrigger) TriggerBuilder.Create().WithIdentity("testTrigger", "testGroup").WithCronSchedule("0/10 * * * * ?").Build(); int i = trig.MisfireInstruction;

_scheduler.ScheduleJob(job, trig);

The only misfireinstruction I can access is trig.MisfireInstruction which is an int, and I can't set it. There are also some functions beginning WithMisfireHandlingInstruction in CronScheduleBuilder.

Was it helpful?

Solution

Your trigger creation should be like this:

trig = (ICronTrigger)TriggerBuilder
       .Create()
       .WithIdentity("testTrigger", "testGroup")
       .WithCronSchedule("0/10 * * * * ?", x => x.WithMisfireHandlingInstructionFireAndProceed())
       .Build();

you can use these options:

  • WithMisfireHandlingInstructionDoNothing
  • WithMisfireHandlingInstructionFireAndProceed
  • WithMisfireHandlingInstructionIgnoreMisfires

You can find a good explanation here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top