Quartz.NET setting MisfireInstruction

微笑、不失礼 提交于 2019-12-10 02:38:19

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/13588627/quartz-net-setting-misfireinstruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!