Guide

Hangfire recurring jobs: cron expressions, time zones and missed runs

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.

The registration, written out

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:

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.

Why your 06:00 job runs at 08:00

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:

Cron syntax in one table

Hangfire parses cron expressions with the Cronos library: minute, hour, day of month, month, day of week.

ExpressionMeaningHelper
*/15 * * * *every 15 minutesCron.MinuteInterval(15)
0 * * * *every hour on the hourCron.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-507:00 on weekdays—
0 0 1 * *midnight on the first of the monthCron.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.

What happens to runs missed during an outage

If the server was down at 06:00, what happens at 06:40 when it comes back is decided by MisfireHandling:

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.

Renaming, removing and pausing

One list, not two

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.

The failure you cannot see in the dashboard

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.

Recap

← All articles Try QueueHawk free →

Know when a recurring job stops running

Heartbeat and error-rate alerts for every Hangfire server. Free for one application.

Start free