Reputation: 1300
I'm using hangfire for scheduling jobs and creating recurring job as:
RecurringJob.AddOrUpdate(() => BackGroundJobManager.FirstJob(), Cron.Daily(4));
This runs the job daily at 4 AM. How can I configure a cron job to run after every 4 hours.
Upvotes: 3
Views: 2943
Reputation: 326
Whilst the HourInterval function is being deprecated, you could just create your own as all it does is return the cron schedule.
public static string HourInterval(int interval)
{
return string.Format("0 */{0} * * *", (object) interval);
}
Upvotes: 1
Reputation: 1319
The cron expression to schedule something every four hours is e.g.:
0 */4 * * *
You could build that expression with Cron.HourInterval(4)
, but it seems to be deprecated. Since those methods just return the cron
expression as a string, you could just build your own and use that instead.
Upvotes: 4