每8天在Hangfire中执行一次周期性工作 [英] Execute a recurring job in Hangfire every 8 days

查看:495
本文介绍了每8天在Hangfire中执行一次周期性工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆