Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HangFire delayed tasks with date

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

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

But what if I need to run task in specific date?

like image 254
Dana Bek Avatar asked Apr 23 '15 13:04

Dana Bek


People also ask

Is Hangfire Russian?

Starting from Mar 8, 2022 Hangfire is owned by Hangfire OÜ (private limited), an Estonian company.

What is latency in Hangfire?

DashboardLatency.PNG890×113 3.68 KB. yngndrw August 20, 2015, 7:22pm #3. Latency is the amount of time between the job being created and the start of the processing of the job: github.com.

What Hangfire object and method is used to create a recurring job?

The call to AddOrUpdate method will create a new recurring job or update existing job with the same identifier.


1 Answers

If the year doesn't matter, you can use cron expression for this purpose. Most default cron implementations (like NCrontab used by Hangfire) don't include the year field.

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

This job will be executed at 4.30am on the 27th of June every year.

like image 150
Jerry Avatar answered Oct 08 '22 06:10

Jerry