我想安排Quartz.Net在每天的特定时间运行多个工作日。时间表应该永远运行。
例如:
我有以下配置,但它没有纪念时间,每次产生的时间是00:00,尽管它是在正确的一天。
DateTimeOffset off = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 12, 0, 0, DateTimeKind.Utc);
var trigger = TriggerBuilder.Create().
WithIdentity("Test").
WithDailyTimeIntervalSchedule(x =>
x.InTimeZone(TimeZoneInfo.Utc).
WithIntervalInHours(24).
OnDaysOfTheWeek(process.RunAtDays)).
StartAt(off).
Build();
此输出如下:
到目前为止,我已经尝试了各种组合,但没有运气。
我相信等效的cron配置是:
"0 00 12 ? * MON,THU,SAT"
但是我需要最终用户可以配置这些值。
答案 0 :(得分:1)
经过几个小时玩价值观后,我相信我有正确的组合来完成任务。我需要将StartingDailyAt()
设置为我想要重复的时间。完成的代码如下所示:
DateTimeOffset off = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 12, 0, 0, DateTimeKind.Utc);
var trigger = TriggerBuilder.Create().
WithIdentity("Test").
WithDailyTimeIntervalSchedule(x =>
x.InTimeZone(TimeZoneInfo.Utc).
WithIntervalInHours(24).
OnDaysOfTheWeek(process.RunAtDays).
StartingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(12, 0, 0))).
StartAt(off).
Build();