9

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Ben Catterall
  • 401
  • 3
  • 14
  • `MisfireInstruction.CronTrigger.FireOnceNow` may be what I'm looking for...? – Ben Catterall Nov 27 '12 at 16:34
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Nov 27 '12 at 16:58

1 Answers1

18

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.

LeftyX
  • 35,328
  • 21
  • 132
  • 193