33

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?

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
  • 3
    You can use this (http://www.cronmaker.com/) to generate cron expressions. And then (as per the accepted answer) you can call RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), cronText); – Dilhan Jayathilake Apr 30 '17 at 04:22

4 Answers4

79

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

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
7

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

RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), Cron.MinuteInterval(15));
Unheilig
  • 16,196
  • 193
  • 68
  • 98
4

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));
Jerry
  • 1,762
  • 5
  • 28
  • 42
2

try the official tool for CronExpression:

https://crontab.guru/#*/15_*_*_*_*
Dongdong
  • 2,208
  • 19
  • 28