Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure cron job that is executing every 15 minutes on Hangfire

Tags:

c#

hangfire

ncron

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?

like image 787
Nikolay Kostov Avatar asked Jan 10 '15 11:01

Nikolay Kostov


People also ask

How do I create a recurring job on hangfire?

Recurring job registration is almost as simple as background job registration – you need to write a single line of code, but you also need to specify an identifier you can use to refer to your job later. The call to AddOrUpdate method will create a new recurring job or update existing job with the same identifier.

How do I run a Cron job every 20 minutes?

For example, if you have 1-10/2 in the Minutes field, it means the action will be performed every two minutes in range 1-10, same as specifying 1,3,5,7,9 . Instead of a range of values, you can also use the asterisk operator. To specify a job to be run every 20 minutes, you can use “*/20”.

How do I schedule a Cron job every 10 minutes?

Run a Cron Job after every 10 minutes The slash operator helps in writing the easy syntax for running a Cron job after every 10 minutes. In this command, */10 will create a list of minutes after every 10 minutes.

What is the cron expression for every 5 minutes?

“At every 5th minute.” Cron job every 5 minutes is a commonly used cron schedule. We created Cronitor because cron itself can't alert you if your jobs fail or never start.


2 Answers

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

like image 108
Nikolay Kostov Avatar answered Sep 16 '22 12:09

Nikolay Kostov


We can also use the following code line to schedule job for every 15 minutes.

RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), Cron.MinuteInterval(15)); 
like image 38
Shantilal Suthar Avatar answered Sep 20 '22 12:09

Shantilal Suthar