11

In Hangfire, what is the difference between a Background job and a recurring job? Because cron support is provided only in recurring job and not in background job?

user2613228
  • 242
  • 1
  • 4
  • 12

1 Answers1

15

Recurring job is meant to trigger in certain intervals i.e. hourly, daily, thus you supply a cron expression.

RecurringJob.AddOrUpdate(
    () => YourRegularJob(), 
    Cron.Daily);

Background job is meant to execute once, either by placing it in the queue and executing immediately or by delaying the job to be executed at specific time.

BackgroundJob.Enqueue(
    () => YourImmediateJob());

BackgroundJob.Schedule(
    () => YourDelayedJob(), 
    TimeSpan.FromDays(3));
Jerry
  • 1,762
  • 5
  • 28
  • 42