justdmitry/RecurrentTasks

TryRunImmediately() not working when interval is 365 days

Closed this issue · 7 comments

I have a lot of scheduled tasks and a 'scheduled taks monitor', where I can see all statuses etc. In the monitor I also implemented a button to fire 'TryRunImmediately'.

This works for all scheduled tasks with, except 2 tasks that have an interval set to 365 days. Some intervals are set to 7 days, they work. What is the maximum TimeSpan for being able to fire TryRunImmediately?

There is no any max/min TimeSpan restrictions.

Code is simple (https://github.com/justdmitry/RecurrentTasks/blob/master/src/RecurrentTasks/TaskRunner.cs#L151-L156):

AutoResetEvent called 'runImmediately' is created in constructor, and Task waits "for it" no more than 'sleepInterval' (e.g., waits for first of them to happen).

Usually 'runImmediately' will not fire, and Task runs after 'sleepInterval'.

When you call 'TryRunImmediately' - event fires, and Task runs.

As you see, there is no any difference how long is 'sleepInterval' for firing 'runImmediately'.

I read the code and had the same conclusion.
But trial and error learns me that the maximum interval where I can use TryRunImmediately() is 24 days.
Really strange why this is...

Tried with Sample app... It seems stop working between 20 and 25 days as Interval.

I think it related with interval as int32, where Int32.MaxValue is max allowed, and TimeSpan.FromMilliseconds(int.MaxValue) is 24 days 20H and 31 min...

Ah too bad.. Is there no method like 'WaitUntil(DateTime)' or so? Then we are not limited?

I got whats happening there... Passing big TimeSpan throws ArgumentOutOfRangeException, and background task interrupts, like after 'Stop'.
I should add checks for Interval in config...

No, there is no any kind of WaitUntil afaik.

If this helps, when I need to wait "for long" (everything more than 1 day for me) I do it as follows:

  • I have "LastSuccessulRun" field/object/value in storage/DB
  • Task runs every 1-2-3-4 hours, checks "LastSuccessfilRun" value and do work only if this value greater than some threshold.

This also prevents task from running "out of schedule" after app restart/republish/etc.

v6.4.1 throws exception when Interval or FirstRunDelay are too big

Ok, thanks.