RecurringJob does not run every 45 seconds as configured in cron expression

recurring
Tags: #<Tag:0x00007f64b4e07908>

#1

I have set the cron expression to /45 * * * * * so that it can run every 45 seconds
Below is the code for the same
RecurringJob.AddOrUpdate(
x => x.DoWork(), "
/45 * * * * *");

What I observed is it configures the next execution e.g at 07:08:45 sec and when it executes it should ideally set next execution at 07:09:30 sec but it sets 07:09:00 means it executes after 15 seconds and then it again sets next execution to 07:09:45.

so what i observed is always sets execution at hh:mm:45 and hh:mm+1:00

So I am not getting the expected output to set recurring job every 45 sec?

It would be really helpful if any one has came across this issue and has got any solution to this.

Hangfire.Core Version used 1.7.6
HangFire.SqlServer version used 1.7.6
HangFire.AspNetCore version used 1.7.6

Application is console application with TargetFramework : .NetCore 2.2


#2

As far as I know, Cron jobs only goes down to minute granularity.

That seems to be the case for hangfire recurring tasks as well:

A special component in Hangfire Server (see Processing background jobs) checks the recurring jobs on a minute-based interval and then enqueues them as fire-and-forget jobs.

https://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html


#3

Thanks for your reply.
This update was made in 1.7.0 to support seconds. Here is the link for the same


#4

maybe it’s a syntax error? shouldn’t there be a * in front of the /45?

*/45 * * * * *


#5

while posting I had put */45 * * * * * but after posting it removed that * but while replying it does show that *.

So I had set the cron expression as you mentioned */45 * * * * *, but not getting the expected result.
Still looking for the solution.


#6

Remove the slash in front of 45. I don’t know why it’s work that way but adding slash also reduced my time by 3 times.