One line to run it later
A job is a call to one of your methods. Its arguments are stored, so the job runs even if the process that created it has gone away.
- Fire-and-forget
- Delayed
- Recurring
- Continuations
- Fan-in
Runs once, as soon as a worker is free. If it throws, it is retried automatically. Learn more
app.MapPost("/users/{id:int}/welcome", (int id, IBackgroundJobClient jobs) =>
{
string? jobId = jobs.Enqueue<EmailService>(x => x.SendWelcome(id));
return Results.Accepted(value: new { jobId });
});
Runs once, later: after a delay, at a moment you choose, or at a time written in plain English. Learn more
jobs.Schedule<ReminderService>(x => x.SendTrialEnding(id), TimeSpan.FromDays(11));
jobs.Schedule<ReminderService>(x => x.SendTrialEnding(accountId), "tomorrow at 9am");
jobs.Schedule<ReportService>(x => x.BuildDaily(), "end of month");
Runs on a CRON schedule, written by hand, with the Cron helpers, or as an English phrase. Learn more
recurringJobs.AddOrUpdate<ReportService>(
"daily-report", // the recurring job ID
service => service.BuildDaily(), // what to run
Cron.Daily(6)); // when: every day at 06:00 UTC
recurringJobs.AddOrUpdate<CleanupService>("purge-sessions", x => x.PurgeExpiredSessions(),
Cron.FromText("every 10 minutes"));
Runs after another job finishes. Creating a job returns null when a filter cancels it. Learn more
string? chargeId = jobs.Enqueue<OrderService>(x => x.ChargeAsync(orderId));
if (chargeId != null)
{
jobs.ContinueJobWith<EmailService>(chargeId, x => x.SendReceipt(orderId));
}
Runs once a whole set of jobs has finished, such as merging exports made in parallel. Learn more
string?[] exports =
{
jobs.Enqueue<ExportService>(x => x.ExportRegionAsync("eu")),
jobs.Enqueue<ExportService>(x => x.ExportRegionAsync("us")),
jobs.Enqueue<ExportService>(x => x.ExportRegionAsync("apac")),
};
jobs.ContinueJobWithAll<ExportService>(exports, x => x.MergeAsync());
Everything a job needs in production
Start with one job. Add retries, limits, schedules and monitoring when you need them, with attributes and configuration rather than new infrastructure.
Retries that back off on their own
A job that throws is retried up to ten times with growing, jittered delays. Add retry-later, in-process retries and circuit breakers when a dependency is down.
Read the guide- 1Attempt 1Failed: HttpRequestException
- 2Retry 1Scheduled in 34 s
- 3Attempt 2Failed: timeout
- 4Retry 2Scheduled in 1 min 2 s
- 5Attempt 3Succeeded
Concurrency control
One at a time, throttling, rate limits and duplicate prevention, across every server.
Read the guideTimeouts and run windows
Job timeouts, deadlines, run windows and blackouts, and how long finished jobs are kept.
Read the guideA dashboard for operators
Live monitoring, search, insights, failure clusters, lineage, a wallboard and a "why isn't it running?" diagnosis.
Read the guideNo reflection
A source generator emits direct calls to your job methods, so they are not invoked through reflection.
Read the guideSchedules in plain English
Cron.FromText turns a phrase into a CRON expression, and Cron.Describe explains one back.
Read the guide| Cron.FromText(...) | CRON |
|---|---|
| "every 15 minutes" | */15 * * * * |
| "weekdays at 9" | 0 9 * * 1-5 |
| "every 10 minutes from 9am to 5pm on weekdays" | */10 9-17 * * 1-5 |
| "last day of month at 23:00" | 0 23 L * * |
Drain mode
Stop starting new jobs for the whole system, a queue or one server, then deploy.
Read the guideAlerts and webhooks
Failures and missed deadlines sent to Slack, Microsoft Teams, Discord or any URL.
Read the guideOpenTelemetry
Traces and metrics for every job through UseTelemetry(), cheap when nobody listens.
Read the guideHealth checks and metrics
ASP.NET Core health checks, plus /health and Prometheus /metrics endpoints for probes and scrapers.
Read the guideOne install for web apps. Pick and mix for the rest.
All five packages ship together with the same version number. ASP.NET Core apps install the meta-package; Worker Services and console apps take only the parts they use.
Masterly.NightShiftCore, SQL Server storage and the ASP.NET Core integration in one install.
Masterly.NightShift.CoreJobs, the server, filters and the dashboard. Add a storage package next to it.
Masterly.NightShift.SqlServerSQL Server storage on Microsoft.Data.SqlClient, with the schema created and upgraded for you.
Masterly.NightShift.NetCoreDependency injection, logging and hosted services for Generic Host apps and Worker Services.
Masterly.NightShift.AspNetCoreDashboard middleware and endpoint mapping, health checks and the metrics endpoint.
Your first job, running in five minutes.
The quick start goes from an empty web app to a job you can watch in the dashboard.