asp.net cron作业quartz.net错误,不总是触发

本文关键字:net 错误 cron 作业 quartz asp | 更新日期: 2023-09-27 18:26:52

我有一个作业,每30分钟触发一次。我已经设置了一个测试表,并在工作被解雇时记录信息。例如:

2015-12-13 19:30:00.043
2015-12-14 12:30:00.043
2015-12-14 13:00:00.043
2015-12-14 16:00:00.043

但正如你所看到的,它并不是每30分钟就会触发一次。19:30然后12:30。我注意到,如果我打开managament工作室并检查此表,下一个工作将触发100%。为什么会发生这种情况,是quartz.net错误吗?P.S我正在使用asp.net mvc,这是代码:

  ITrigger trigger = TriggerBuilder.Create()
                   .WithDailyTimeIntervalSchedule
                     (s =>
                        s.WithIntervalInMinutes(30)
                        .OnEveryDay()
                       .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
                     )
                   .Build();
               scheduler.ScheduleJob(job, trigger);

asp.net cron作业quartz.net错误,不总是触发

需要将WithDailyTimeIntervalSchedule更改为WithSimpleSchedule。警告:可能有更好的方法来处理startDate

DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0 ,0, DateTimeKind.Utc);
 ITrigger trigger = TriggerBuilder.Create()
.StartAt(new DateTimeOffset(startDate, new TimeSpan(0)))
.WithSimpleSchedule
(s =>
    s.WithIntervalInMinutes(30)
    .RepeatForever()
)                   
.Build();

测试:

var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times)
    Console.WriteLine(time.UtcDateTime);
Console.ReadKey();

结果:

14.12.2015 15:00:00
14.12.2015 15:30:00
14.12.2015 16:00:00
14.12.2015 16:30:00
14.12.2015 17:00:00
14.12.2015 17:30:00
14.12.2015 18:00:00
14.12.2015 18:30:00
14.12.2015 19:00:00
14.12.2015 19:30:00