Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public static IDisposable ScheduleCron(this IScheduler scheduler, string cron, A
// When this gets cancelled we only need to actually dispose of the most recent scheduled action
// (there will only be one at a time) so we store that in a box we will pass down
StrongBox<IDisposable?> disposableBox = new();
RecursiveSchedule(scheduler, CronExpression.Parse(cron), action, disposableBox);
RecursiveSchedule(scheduler, CronExpression.Parse(cron), action, disposableBox, scheduler.Now);

// Dispose will Dispose the IDisposable in the box
return Disposable.Create(()=> disposableBox.Value?.Dispose());
}

private static void RecursiveSchedule(IScheduler scheduler, CronExpression cronExpression, Action action, StrongBox<IDisposable?> disposableBox)
private static void RecursiveSchedule(IScheduler scheduler, CronExpression cronExpression, Action action, StrongBox<IDisposable?> disposableBox, DateTimeOffset now)
{
var next = cronExpression.GetNextOccurrence(scheduler.Now, TimeZoneInfo.Local);
var next = cronExpression.GetNextOccurrence(now, TimeZoneInfo.Local);
if (next.HasValue)
{
disposableBox.Value = scheduler.Schedule(next.Value, EcecuteAndReschedule);
Expand All @@ -47,7 +47,7 @@ void EcecuteAndReschedule()
}
finally
{
RecursiveSchedule(scheduler, cronExpression, action, disposableBox);
RecursiveSchedule(scheduler, cronExpression, action, disposableBox, next.Value);
}
}
}
Expand Down