I am using Hangfire and like the software very much! But one thing I am missing is how to add a recurring job that executes every few minutes (e.g. every 15 minutes). Is there a way to achieve this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Currently I am using this approach:
RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), "*/15 * * * *");
And is working like a charm.
Reference to my question in Hangfire forums: http://discuss.hangfire.io/t/how-to-create-cron-job-that-is-executing-every-15-minutes/533
回答2:
Looking at Hangfire.Cron class I don't know if it's possible.
A workaround would be to create four different schedules i.e:
RecurringJob.AddOrUpdate(
() => Console.WriteLine("Transparent!"),
Cron.Hourly(0));
RecurringJob.AddOrUpdate(
() => Console.WriteLine("Transparent!"),
Cron.Hourly(15));
RecurringJob.AddOrUpdate(
() => Console.WriteLine("Transparent!"),
Cron.Hourly(30));
RecurringJob.AddOrUpdate(
() => Console.WriteLine("Transparent!"),
Cron.Hourly(45));
回答3:
We can also use the following code line to schedule job for every 15 minutes.
RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), Cron.MinuteInterval(15));