Skip to main content

Recurring Jobs

To run a handler on a schedule, put a schedule attribute on it. JobMaster registers the schedule when the app starts; there is nothing to call.

Natural Language​

[NaturalCronSchedule] takes a NaturalCron expression. It's built in:

using JobMaster.Abstractions.StaticRecurringSchedules;

[JobMasterDefinitionId("inventory-sync")]
[NaturalCronSchedule("every 5 minutes")]
public sealed class InventorySyncHandler : IJobMasterHandler
{
public async Task HandleAsync(JobContext job) { ... }
}

A handler can have more than one schedule:

[NaturalCronSchedule("every day at 09:00")]
[NaturalCronSchedule("every day at 18:00")]
public sealed class DailyReportHandler : IJobMasterHandler { ... }

Times are in the cluster's time zone, unless the expression names one ("every day at 09:00 tz America/New_York").

Fixed Interval​

[TimeSpanIntervalSchedule] runs the handler at a fixed interval, written as a TimeSpan (hh:mm:ss). It's built in too:

[TimeSpanIntervalSchedule("00:10:00")] // every 10 minutes
public sealed class CleanupHandler : IJobMasterHandler { ... }

Standard Cron​

NaturalCron and fixed intervals are built in. Other recurrence engines come as separate packages you add when you need them, and you can also write your own.

For standard cron syntax, add the JobMaster.Cronos package:

dotnet add package JobMaster.Cronos --prerelease

Register it before AddJobMasterCluster, then use [CronosSchedule]:

using JobMaster.Cronos;

builder.Services.AddJobMasterCronos();
builder.Services.AddJobMasterCluster(config => { ... });
[CronosSchedule("0 18 * * 1-5")] // 18:00 on weekdays
public sealed class RenewalHandler : IJobMasterHandler { ... }

JobMaster.NCrontab works the same way, with AddJobMasterNCrontab() and [NCrontabSchedule].

Handler Settings Still Apply​

The attributes from Scheduling Jobs ([JobMasterTimeout], [JobMasterMaxNumberOfRetries], …) also apply to every run of a recurring schedule.

More​

Schedules created from code at runtime (for example one per customer), schedule profiles, start and end dates and custom engines are covered in Recurring Schedule.

Next​

Cluster Basics: defaults for the whole cluster (timeout, retries, time zone and data retention).