我有两项任务。第一个应该每小时执行一次,第二个应该每天执行12:00。第一个任务的触发器工作正常,但第二个任务的触发器仅在目标时间前几分钟创建时触发。我做错了什么?
第一个的配置:
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();
第二个:
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();
计划程序配置:
<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>
答案 0 :(得分:0)
您的Trigger定义似乎没有错。但Quartz(2.x)的编写并不是很好,有时可能会非常奇怪。 你的第二个Trigger是一个CronTrigger,可以用其他方式定义。
这对我有用:
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();