Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz.NET setting MisfireInstruction

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.

like image 815
Ben Catterall Avatar asked Nov 27 '12 16:11

Ben Catterall


People also ask

What is quartz misfire?

A misfire occurs if a persistent trigger “misses” its firing time because of the scheduler being shutdown, or because there are no available threads in Quartz's thread pool for executing the job. The different trigger types have different misfire instructions available to them.

What is trigger in quartz?

Trigger - a component that defines the schedule upon which a given Job will be executed. JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.


1 Answers

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.

like image 173
LeftyX Avatar answered Oct 08 '22 13:10

LeftyX