Execute a recurring job in Hangfire every 8 days

后端 未结 2 1716
执念已碎
执念已碎 2021-02-07 11:16

Is it possible to create a recurring job in Hangfire that executes after a given number of days, say 8.

The nearest I found was to execute a job once in a week -

<
相关标签:
2条回答
  • 2021-02-07 11:37

    A more cleaner Solution will be to use Cron.DayInterval(interval).

    For your case it will be

    RecurringJob.AddOrUpdate("MyJob",() => ScheduledJob(), Cron.DayInterval(8));
    
    0 讨论(0)
  • 2021-02-07 11:44

    Finally I have used CronExpression like this to schedule a recurring job with frequency of every 8 days or for any number of days for that matter.

    string cronExp = "* * */8 * *";
    RecurringJob.AddOrUpdate("MyJob",() => ScheduledJob(), cronExp);
    

    The third segment in CronExpression represents day of month.

    The respective segments are as follows - (Ref: https://en.wikipedia.org/wiki/Cron)

    0 讨论(0)
提交回复
热议问题