问题
I have two tasks. The first should be execute once an hour, and the second every day at 12:00. The trigger of the first task works fine, but the second fires only if it is created a few minutes before the target time. What am I doing wrong?
The configuration of the first:
IJobDetail job = JobBuilder.Create<WatchJob>()
.WithIdentity("Job_1", "First")
.WithDescription("Job_1_First")
.UsingJobData("AppData", JsonConvert.SerializeObject("Job_1_First"))
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("Trigger_1", "First")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(1440)
.RepeatForever())
.Build();
And the second:
IJobDetail updateJob = JobBuilder.Create<UpdateJob>()
.WithIdentity("Job_1", "Second")
.WithDescription("Job_1_Second")
.UsingJobData("AppData", JsonConvert.SerializeObject("Job_1_Second"))
.Build();
ITrigger updateTrigger = TriggerBuilder.Create()
.WithIdentity("Trigger_1", "Second")
.WithDailyTimeIntervalSchedule
(t => t
.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(12, 0))
)
.Build();
Scheduler configuration:
<quartz>
<add key="quartz.scheduler.instanceName" value="Test" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="1" />
<add key="quartz.threadPool.threadPriority" value="2" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
</quartz>
回答1:
It seems nothing wrong with your Trigger definition. But Quartz(2.x) is not so well written under the hood and can sometimes act really strange. Your second Trigger is a CronTrigger and can defined in an other way.
This works for me:
ITrigger updateTrigger = TriggerBuilder.Create()
.WithIdentity("Trigger_1", "Second")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(12, 0))
// this line tells quartz to start the trigger immediately, you can remove it, if you don't want this behaviour
.StartAt(DateTime.Now.AddDays(-1))
.Build();
来源:https://stackoverflow.com/questions/44231855/quartz-net-trigger-doesnt-fire