A recurring job is one line of code — and the source of most “why didn't the report run?” questions. The schedule runs in a different time zone than you think, an outage swallowed three runs, or a renamed job keeps running under its old name. Here is how Hangfire's recurring jobs actually behave in version 1.8, and the settings that prevent the usual surprises.
RecurringJob.AddOrUpdate<ReportJob>(
"reports.daily", // explicit, stable ID
"default", // queue
job => job.RunAsync(),
"0 6 * * *", // 06:00 ...
new RecurringJobOptions
{
TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Zurich"), // ... Zurich time
MisfireHandling = MisfireHandlingMode.Relaxed,
});
Three things in there are deliberate:
TypeName.MethodName — rename the class, and you have a second recurring job while the first one keeps running.RecurringJobOptions.QueueName is obsolete in 1.8; the overload with an explicit queue replaces it and, according to the upgrade guide, makes re-queueing work as expected.RecurringJobOptions; the old optional parameters are deprecated.AddOrUpdate creates the job or updates the one with the same ID, so calling it at every application start is the normal pattern. IDs should be unique and may be case-sensitive, depending on the storage.
The default time zone of a recurring job is UTC. "0 6 * * *" without options means 06:00 UTC — 08:00 in Zurich in summer, 07:00 in winter. The schedule shifts by an hour twice a year, and nobody changed anything.
Set TimeZone explicitly for every job whose time matters to a human. Two practical notes:
FindSystemTimeZoneById reads the operating system's zone database; minimal container images do not always ship it, and the call throws. Either install the zone data in the image or fall back to UTC deliberately and log it — do not let a missing zone stop the application from starting.Hangfire parses cron expressions with the Cronos library: minute, hour, day of month, month, day of week.
| Expression | Meaning | Helper |
|---|---|---|
*/15 * * * * | every 15 minutes | Cron.MinuteInterval(15) |
0 * * * * | every hour on the hour | Cron.Hourly() |
20 4,9,13,17 * * * | 04:20, 09:20, 13:20 and 17:20 | — |
15 6-20/2 * * * | every two hours from 06:15 to 20:15 | — |
0 7 * * 1-5 | 07:00 on weekdays | — |
0 0 1 * * | midnight on the first of the month | Cron.Monthly() |
0 0 31 2 * | never (February 31st) | Cron.Never() |
The Hangfire server checks recurring jobs on a minute-based interval, so a schedule finer than a minute gains you nothing. To see what an expression means and when it fires next — in UTC or your local zone — paste it into our cron expression explainer.
If the server was down at 06:00, what happens at 06:40 when it comes back is decided by MisfireHandling:
Relaxed (default) — exactly one job is created, no matter how many occurrences were missed.Strict — one job for every missed occurrence, each with its scheduled time. Right for jobs that must process every interval exactly once (“import the 06:00 file, then the 07:00 file”).Ignorable — no job at all for missed occurrences; the next regular one runs. Right for jobs where a late run is worse than none (“send the morning digest”).The default is sensible for most jobs. Decide explicitly for the ones where it is not — an hourly import after a three-hour outage under Relaxed silently skips two hours.
RecurringJob.RemoveIfExists("old-id") next to the new registration; it does not throw if the job is already gone.Cron.Never(): the job stays visible and can still be triggered by hand. The dashboard shows it as 0 0 31 2 * — a date that never comes. Search for that string after every deployment; a job you believe is scheduled may be sitting on it.RecurringJob.TriggerJob("id") (or the dashboard button). A manual run does not reset the schedule: a weekly Wednesday job triggered on Friday still runs next Wednesday.A pattern we see often: production and development register their recurring jobs in two separate branches that slowly drift apart, until a job exists in one and not the other. Register every recurring job once, with its schedule per environment side by side — and if some environments must not run a job automatically, use Cron.Never() there instead of leaving it out. Our sister product Tenderis learnt this the expensive way.
A recurring job that never runs never fails. The dashboard shows “next execution” — not that the last three didn't happen because the server was down or the job sat on Cron.Never(). A job that ran and threw shows up as Failed; a job that never started shows up as nothing at all.
QueueHawk covers the first half of this from outside the process: a heartbeat alert when no Hangfire server of an application has checked in, and error-rate alerts per job type. For the schedule itself, write down per job how you would notice it did not run — the newest imported record, the last digest sent — and turn that check into a small job of its own that fails when the answer is wrong.
TimeZone. Set it, and plan for containers without zone data.MisfireHandling: Relaxed (one catch-up run, default), Strict (every missed run), Ignorable (none).RemoveIfExists; look for 0 0 31 2 * after every deploy.Heartbeat and error-rate alerts for every Hangfire server. Free for one application.