I'm trying to fire a job every morning at 8AM, UTC time. The problem is the triggers aren't respecting the time I'm telling it.
My code is as follows:
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(
s => s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8,0)))
.Build();
var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times)
Console.WriteLine(time.UtcDateTime);
The output is:
30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 10:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM
The reason the hour changes on the 6th is that daylight savings time starts here this weekend.
How do I get it to just trigger at 8AM UTC time like I'm telling it to?
Edit: This is crazy, it even does it with the Cron schedule:
ITrigger trigger = TriggerBuilder.Create()
.WithCronSchedule("0 0 8 * * ?")
.Build();
var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times)
Console.WriteLine(time.UtcDateTime);
Output:
30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 9:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM
After pulling down the source code and digging through, I've found a couple of solutions.
I originally found a solution like so:
var trigger4 = new DailyTimeIntervalTriggerImpl
{
StartTimeUtc = DateTime.UtcNow,
StartTimeOfDay = new TimeOfDay(8, 0, 0),
RepeatIntervalUnit = IntervalUnit.Hour,
RepeatInterval = 24,
TimeZone = TimeZoneInfo.Utc
};
...which led me to adjust my original code:
ITrigger trigger2 = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(
s => s.WithIntervalInHours(24)
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))
.InTimeZone(TimeZoneInfo.Utc))
.Build();
Both of these give me what I'm after. I just wish there was some decent documentation out there for this library.