I need to schedule a job which should fire daily using QUARTZ Daily Simple Scheduler. I have gone through the whole documentation and nothing helped me out.
I have the following code:
var builder = TriggerBuilder.Create()
.WithDescription(key + group)
.WithIdentity(trigKey)
.StartAt(startDate.Value.ToLocalTime())
.WithDailyTimeIntervalSchedule(
s => s.OnEveryDay()
.WithIntervalInHours(24)
.StartingDailyAt(
TimeOfDay.HourAndMinuteOfDay(
startDate.Value.ToLocalTime().Hour,
startDate.Value.ToLocalTime().Minute)));
var newTrigger = builder.Build();
Scheduler.ScheduleJob(addNewJob, trig);
This seems to work with one problem. If I schedule the job for yesterday at 12:10 it will run today at 12:10. However, if I schedule it for today at 12:10 it will nor run today. I tried it a couple of times. Scheduling it at 12 to execute at 12:30 (thought it might need more time) but nothing seemed to work. I checked in the DB and the StartTime is correct. I have a hunch that QUARTZ might be setting the job to execute for the day after the job is scheduled.
And currently I am stuck. I know that this can be accomplished with CRON triggers but I need it with the Daily simple scheduler.
I found the problem. The .WithIntervalInHours(24)
is adding 24 hours to the start time and if it scheduled for today it will run tomorrow. Removing it did the trick.