HangFire Delays Job with Date

How to add a date to a HangFire task? For example, this code adds 7 days:

BackgroundJob.Schedule( () => Console.WriteLine("Reliable!"), TimeSpan.FromDays(7)); 

But what if I need to run a task on a specific date?

+8
date task hangfire
source share
2 answers

If the year does not matter, you can use the cron expression for this purpose. Most standard cron implementations (such as NCrontab used by Hangfire) do not include the year field.

 BackgroundJob.Schedule( () => Console.WriteLine("Reliable!"), "30 4 27 6 *"); 

This work will be performed at 4.30am on June 27 of each year.

+5
source share

As the developer answered my question here , you can simply use the date instead of the day (s).

 BackgroundJob.Schedule( () => Console.WriteLine("Reliable!"), new DateTime(2015, 08, 05, 12, 00, 00)); 

For 08/05/2015 at 00:00.

Jerry's answer is correct for RecurringJobs

 RecurringJob.Schedule( () => Console.WriteLine("Reliable!"), "00 00 05 8 *"); 

which will be launched every year 05/08 at 00:00

+3
source share

All Articles