每8天在Hangfire中执行一次周期性工作 [英] Execute a recurring job in Hangfire every 8 days
问题描述
是否可以在Hangfire中创建一个重复的工作,该工作在给定的天数(例如8天)后执行。
我发现最近的一次是执行一次工作一周内-
RecurringJob.AddOrUpdate( MyJob,()=> ScheduledJob(),Cron.Weekly() );
了解Hangfire还接受标准的 CronExpression
,我曾尝试探索此频率的cron表达式,但找不到它-
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 -
RecurringJob.AddOrUpdate("MyJob",() => ScheduledJob(), Cron.Weekly());
Understanding that Hangfire also accepts standard CronExpression
, I've tried exploring cron expression for this frequency but couldn't found one for it-
https://en.wikipedia.org/wiki/Cron
One ugly solution could be to create 3 or 4 jobs that executes once in month at some dates accordingly, but I don't want to do that.
Any suggestions please.
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)
这篇关于每8天在Hangfire中执行一次周期性工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!