Skip to main content

Recurring Schedule

A recurring schedule runs a handler at every occurrence of an expression ("every day at 09:00", every 10 minutes, a cron expression). Each occurrence is a job of its own, with its own retries.

There are two kinds:

  • From code: created by a call at runtime, often one per entity (a subscription renewal, a report per customer), and each can carry its own message data. This page covers them.
  • Static: declared in code (an attribute or a profile) and registered when the app starts, for fixed system routines. See Static Schedules.

Recurrence Engines​

The expression is read by a recurrence engine:

EngineExpressionPackage
TimeSpan intervalTimeSpan.FromMinutes(10), or "00:10:00"built in
NaturalCron"every day at 09:00", "every 30 minutes between 09:00 and 18:00"built in
Cronos"0 18 * * 1-5" (5 fields, or 6 with seconds)JobMaster.Cronos
NCrontab"0 18 * * 1-5" (5 fields, or 6 with seconds)JobMaster.NCrontab

Cronos and NCrontab read the same syntax; pick the one you already know. Register it before AddJobMasterCluster:

builder.Services.AddJobMasterCronos(); // or AddJobMasterNCrontab()
builder.Services.AddJobMasterCluster(config => { ... });

You can also plug in your own engine; see Custom Recurrence Engines.

Time zones. Occurrences are computed in the cluster's time zone (its IanaTimeZoneId; see Cluster Basics). A NaturalCron expression can name its own: "every day at 09:00 tz America/New_York".

Interval vs. clock. A TimeSpan or NaturalCron interval counts from when the schedule starts. A cron expression follows the clock: */5 * * * * runs at :00, :05, :10 … of every hour.

Creating a Schedule from Code​

One method per engine:

var data = WriteableMessageData.New().SetStringValue("SubscriptionId", "sub_123");

await scheduler.RecurringAsync<CleanupHandler>(TimeSpan.FromMinutes(10));
await scheduler.NaturalCronRecurringAsync<RenewalHandler>("every month", data);
await scheduler.CronosRecurringAsync<RenewalHandler>("0 18 * * 1-5", data); // JobMaster.Cronos
await scheduler.NCrontabRecurringAsync<RenewalHandler>("0 18 * * 1-5", data); // JobMaster.NCrontab

NaturalCron also has a builder:

var expr = NaturalCronBuilder
.Every(30).Minutes()
.Between("09:00", "18:00")
.Build();

await scheduler.RecurringAsync<ReportHandler>(expr);

Any engine, including a custom one, can be used by its type id: scheduler.RecurringAsync<RenewalHandler>(NaturalCronExprCompiler.TypeId, "every day at 18:00").

Each method also has a synchronous version (Recurring, NaturalCronRecurring, …).

Options​

A schedule takes the same options as a one-off job, applied to every run, plus a start and an end:

ParameterSets
dataThe message data passed to every run
clusterId, priority, workerLane, timeout, maxNumberOfRetries, metadataAs for a one-off job
startAfterNo run before this UTC time
endBeforeRuns only before this UTC time, never at or after it
await scheduler.NaturalCronRecurringAsync<ReportHandler>(
"every day at 06:00",
priority: JobMasterPriority.Low,
workerLane: "reports",
endBefore: new DateTime(2027, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Start and End Dates​

The first run comes after startAfter, and runs happen only before endBefore. An occurrence exactly on endBefore doesn't run.

For example, a schedule running daily at 00:00 UTC with endBefore on 31 Oct 2026 runs for the last time on 30 Oct 2026 at 00:00; nothing runs on 31 Oct, not even at exactly 00:00. In other words, pass the first moment you no longer want it to run. Once endBefore is reached, the schedule becomes Inactive.

Where Each Setting Comes From​

As for one-off jobs, a setting the schedule doesn't set comes from the handler's attribute, then from the cluster's default or JobMaster's own (see the table). For metadata, the schedule's own keys override the handler's [JobMasterMetadata] key by key.

Priority, timeout and retries are resolved again for every run, so a changed handler attribute applies to the next run.

Statuses​

A recurring schedule has its own status, separate from the jobs it creates:

StatusDescription
PendingSaveCreated, not saved yet on the cluster's database.
ActiveRunning and creating jobs.
CanceledStopped before its end: final.
InactivePast its endBefore, or a static schedule no app declares anymore: final.
CompletedIts expression has no occurrence left: final.

The final statuses are what DataRetentionTtl and Archiving mean by "terminated recurring schedules".

Sub-minute schedules

Schedules shorter than a minute work, but runs can overlap and a start delay of 10–20 seconds is normal in a distributed cluster. For work that needs second-level precision, a .NET IHostedService or your own background loop fits better. See Avoid Sub-minute Recurring Schedules.

Next​

Static Schedules: schedules declared in code (attributes and profiles).