我暂时使用quartz来重复任务,而且效果很好。出于某种原因,我需要创建一个在两天内运行的任务。以下是我的实施:
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail jobWeekEnd = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
ITrigger triggerWeekend = TriggerBuilder.Create()
.WithIdentity("Foo", "Bar")
.WithCronSchedule("0 0 9 ? * SAT-SUN")
.ForJob(jobWeekEnd)
.Build();
scheduler.ScheduleJob(jobWeekEnd, triggerWeekend); // WORKS WELL
var jobNonWorkingDay = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
var trigger1 = TriggerBuilder.Create()
.WithIdentity("Foo2", "Bar")
.StartAt(new DateTimeOffset(new DateTime(2017, 04, 17, 09, 00, 00)))
.ForJob(jobNonWorkingDay)
.Build();
scheduler.ScheduleJob(jobNonWorkingDay, trigger1);
var jobNonWorkingDay2 = JobBuilderExtend.Create<CreateConsultationReplayJob>(() => new StandardContextProvider());
var trigger2 = TriggerBuilder.Create()
.WithIdentity("Foo3", "Bar3")
.StartAt(new DateTimeOffset(new DateTime(2017, 05, 01, 09, 00, 00)))
.ForJob(jobNonWorkingDay2)
.Build();
scheduler.ScheduleJob(jobNonWorkingDay2, trigger2);
trigger1和trigger2似乎没有在正确的时间触发,但每次我回收池时,最后一次发生的时间是11:16:15。
关于我应该挖掘的地方的任何线索?
答案 0 :(得分:0)
由于第一个调度程序的日期是过去的(new DateTime(2017, 04, 17, 09, 00, 00)
)并且未定义EndAt
,因此触发器在启动时触发一次。从这个信息,有两个选项:
EndAt()
设置结束值 - 快速清洁