If given time interval in Minute is greater than 60 when job will execute

recurring
Tags: #<Tag:0x00007f499a05aa60>

#1

Hi Team,

Thanks for such great system!

I have created a recurring job and given interval in min like below
RecurringJob.AddOrUpdate(() => sendMail(), Cron.MinuteInterval(5000000), TimeZoneInfo.Local);

  1. But this job getting executed every hr. Is it correct or something is wrong.

  2. In Hangfire all tables dates are saved in UTC format I need in local format is there any option for that.

Kindly help.
Thanks in advance!

Thanks & Regards
Sunita


#2

Actually, I ran into the same problem and had to read more about cron expressions. Please check this SO post - https://stackoverflow.com/questions/745901/how-to-do-a-cron-job-every-72-minutes. I did not try this approach with Hangfire, though, but at least it explains why it behaves that way :slight_smile:

P.S. approximately expected behavior probably can be achieved using following expression (however, I just got a thought and did not test it yet :slight_smile: , however, cron expression descriptor says it should work as expected)

        public static string GetCronExpression(this int intervalMinutes) {
            var timeSpan = TimeSpan.FromMinutes(intervalMinutes);
            return $"{timeSpan.Minutes} */{timeSpan.Hours} * * *";
        }

Update: code above works only up to 1439 minutes (24h - 1 minute)