Hangfire Missed Jobs
We had been wondering how Hangfire handles recurring jobs that were not processed if our application was down. We found that Hangfire has a built-in feature to handle this scenario.
It’s MisfireHandling
property of RecurringJobOptions
class.
RecurringJob.AddOrUpdate<IHeartbeatClient>("Heartbeat",
service => service.SendAsync(HeartbeatTypes.Hangfire), Cron.Hourly,
new RecurringJobOptions
{
MisfireHandling = MisfireHandlingMode.Ignorable,
});
MisfireHandlingMode
has three options:
Relaxed
- Only a single job will be created, not matter how many times the schedule was missed.Ignore
- Ignore the misfire, don’t create any jobs and continue with the next schedule.Strict
- Creates a job for every missed occurrence.
The default value is Relaxed
.