Schedule Issue with Cron.HourInterval

Hi

I have an app that sets up scheduled jobs in hangfire and I am getting some strange execution times.

I create a job and use Cron.HourInterval(23). I would expect this to run every 23 hours from the point of creation.

This method gives me the following CRON expression: 0 */23 * * *

However I get the following:

Created: 20/12/2016 16:57:13

Following executions:
22-Dec-2016 00:00:01
21-Dec-2016 23:00:00
21-Dec-2016 00:00:02
20-Dec-2016 23:00:01

Its firstly running on the 23rd hour, not every 23 hours, then for some reason it drops another execution in at midnight.

Ideas?

Thanks in advance.

1 Like

Anyone got any thoughts on this? as its holding up our development and needs to be rectified before release into our production environment.

Thanks in advance.

Mark

Worked out what is going on here, and to be honest the method is miss leading to what it actually does.

HourInterval seems that it will fire a job every n number of hours, this is correct as long as you dont go over 12 hours. If you go any higher then it will run on that hour and then again at midnight. Looks like this is down to how hangfire relies on NCrontab to determine the next execution time. NCrontab only seems to work it out within a complete 24 period. For example. I say I want it to run every 7 hours, so it will run at the following times:

0
7
14
21
then it resets
0
7
etc
etc

This either needs to be documented or fixed because it took we a while to work this out and its not what I was expecting it to do. Surely it should also take the creation time into account and use that as a starting point, i.e. I created it at 2pm, so first time it should run should be 9pm. That doesnt appear to be considered in NCrontab.

Is this something that you will be addressing or is it simply how it is?

I assume minutes and days work in the same way? i.e. don’t go over 30 mins or 14 days.

1 Like

Try using * 0/7 * * * * this says that starting from 0 hours every 7 hours… We are using this try it out

1 Like

Sorry I added one extra * before. This is the right one * 0/7 * * *

1 Like