Asp.net cron job quartz.net error, not always shooting

I have a job that fires every 30 minutes. I set up a test pattern and record information when the work is triggered. For example:

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

But, as you can see, this does not work every 30 minutes. 19:30, and then 12:30 .. I noticed that if I open the management studio and run this table, the next job will cause 100%. Why is this happening, is it a quartz.net error? PS I am using asp.net mvc and this is the code:

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

               scheduler.ScheduleJob(job, trigger);
+4
source share
1 answer

Required to change WithDailyTimeIntervalScheduleto WithSimpleSchedule. Warning: there are probably better ways to deal with it 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();

Test:

var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);

foreach (var time in times)
    Console.WriteLine(time.UtcDateTime);

Console.ReadKey();

Result:

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
+2

Source: https://habr.com/ru/post/1619890/


All Articles