-1

I have a few jobs configured to be executed on an ASP.NET MVC Site through Hangfire. Hangfire uses a cron expression to trigger said jobs. I thought I had the expression correct, but the triggering is happening too often. Image of cron schedule

As you can see, the top job just finished executing 6 minutes previously and its next execution is expected to happen in an hour. But the cron expression, as I understand it, says it should only trigger once a day at 2 AM. Even accounting for different time zones, it shouldn't be happening on an hourly basis.

Do I have the cron expression incorrect? I will admit to not being completely knowledgeable about that, though from my reading I thought I had it correct.

Thanks

Peter Lange
  • 2,786
  • 2
  • 26
  • 40
  • 1
    Not all `cron` implementations understand the `*/1` notation. Wouldn't `*` do just as well there? – Tim Roberts Apr 08 '21 at 21:27
  • Logically, that sounds right. I don't know enough to say for sure, but I can give it a shot. – Peter Lange Apr 08 '21 at 21:34
  • So I just deployed it to the server again this morning with the suggested change, but the frequency is still every hour or so. Thanks for the suggestion though. – Peter Lange Apr 09 '21 at 15:15

1 Answers1

1

Old question, but every time I forget this, I end up back here...

Hangfire (at least the version pictured) uses NCrontab (https://github.com/atifaziz/NCrontab) which allows CRON expressions of 5 or 6 parts. If you use 6 parts, the first part is seconds, the second part is minutes. This is why the job in the pictured example was ran at 3:02.

Most answers I have run across seem to only show the 5 part version of CRON expressions.

From the above URL:

* * * * * *
- - - - - -
| | | | | |
| | | | | +--- day of week (0 - 6) (Sunday=0)
| | | | +----- month (1 - 12)
| | | +------- day of month (1 - 31)
| | +--------- hour (0 - 23)
| +----------- min (0 - 59)
+------------- sec (0 - 59)

To trigger once daily at 2am would be 0 0 2 * * ?