Search code examples
c#asp.net-corehangfire

Hangfire Cron Jon Asp Net Core to start at X time and stop at N time and run every Y minutes


I am trying to implement Hangfire into my Application with Mediator.

So I am able to run hangfire easily but I am having trouble on how to setup a time schedule.

So I am thinking of running the job schedule X to Y time period daily and to run Every N minutes. The N will always be divisible by 60 -> 1,2,3,4,5,6,10,12,15,30,60.

So Lets Suppose time is:

X = 8 AM

Y = 6 PM

N = 5

So according to my hangfire job it should run

8:00 AM
8:05 AM
8:10 AM

Also if the program gets closed and it runs at suppose 2:02 PM then it should start to run like this

2:05 PM
2:10 PM
2:15 PM

So Here is my approach for this.

this Cron Expression

0/5 8-18 * * *

This Cron Expression was built by this link

But is this the best way to do it?


Solution

  • So after some research and retires

    0/5 9-18 * * mon-fri

    This translates to Run Every 5th minute from 9 AM to 6 PM (18) and from Monday to Friday only The above crop job string was successful