Skip to content

About

Source-generated background job scheduler for .NET 8 and .NET 10. Decorate a class with [Job] and the Roslyn generator wires up the executor, DI registration, and recurring startup — no reflection at runtime.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

502 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZeroAlloc.Scheduling

NuGet Build codecov License: MIT AOT GitHub Sponsors

Source-generated background jobs for .NET: mark a class with [Job] and get one-off, delayed and cron jobs with retries, durable stores and a dashboard, with no runtime registration cost and NativeAOT support.

Why ZeroAlloc.Scheduling

  • No runtime registration cost. [Job] registration is generated at compile time. Coravel's Schedule() allocates 696 B per call, measured in the same run.
  • Dispatch costs what a hand-written timer costs. BenchmarkDotNet cannot tell a ZA.Scheduling dispatch from an empty method, just as it can't for a direct call. A test asserts the worker allocates nothing per job beyond the JobContext it hands to the job.
  • Works under NativeAOT and trimming. Executors and DI registration are generated, with no reflection or assembly scanning. CI publishes and runs an AOT app over the in-memory, ORM and Redis stores and the Mediator, Resilience and Telemetry bridges.
  • Compile-time diagnostics. The generator flags jobs it cannot register, such as nested or generic job types or two jobs that would get the same registration method.

Install

dotnet add package ZeroAlloc.Scheduling
dotnet add package ZeroAlloc.Scheduling.InMemory

The source generator ships inside ZeroAlloc.Scheduling. Swap the in-memory store for EF Core, ZeroAlloc.ORM or Redis in production.

Quick start

using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ZeroAlloc.Scheduling;
using ZeroAlloc.Scheduling.InMemory;
using ZeroAlloc.Serialisation;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSerializerDispatcher(); // generated, AOT-safe job serializer
builder.Services.AddScheduling(o => o.PollingInterval = TimeSpan.FromMilliseconds(100))
    .WithInMemoryStore()          // or EfCore, Orm or Redis in production
    .AddSendWelcomeEmailJob();    // generated for the [Job] class
using var host = builder.Build();
await host.StartAsync();

var scheduler = host.Services.GetRequiredService<IScheduler>();
await scheduler.EnqueueAsync(new SendWelcomeEmailJob { To = "alice@example.com" });
await Task.Delay(500); // the worker picks it up, with retries if it throws
await host.StopAsync();

[Job(MaxAttempts = 5)]
[ZeroAllocSerializable(SerializationFormat.SystemTextJson)]
public sealed class SendWelcomeEmailJob : IJob
{
    public required string To { get; init; }

    public ValueTask ExecuteAsync(JobContext ctx, CancellationToken ct)
    {
        Console.WriteLine($"Welcome mail to {To}, attempt {ctx.Attempt}");
        return ValueTask.CompletedTask;
    }
}

[JsonSerializable(typeof(SendWelcomeEmailJob))]
internal sealed partial class AppJson : JsonSerializerContext;

For a recurring job, use [Job(Cron = "0 * * * *")] or [Job(Every = Every.Hour)]: the generator also emits a hosted service that schedules it at startup. The getting started guide covers delays, retries and stores.

What you get

  • One-off jobs, delayed jobs and recurring jobs from cron expressions or fixed intervals.
  • Exponential-backoff retry per job or globally, then dead-lettering.
  • A background worker that polls the store in batches and runs each job through its generated executor.
  • Targets .NET 8, 9 and 10.

Stores and integrations:

Scheduler dashboard

Performance

Against Coravel 6.0.2 and a hand-rolled BackgroundService + Timer. BenchmarkDotNet 0.15.8, .NET 10.0.13, measured 2026-10-15. Allocations are exact; speed is a same-run ratio, because the benchmark host is a shared VM.

Operation Coravel Hand-rolled Timer ZA.Scheduling
Register one job 696 B per Schedule() call — none at runtime, generated at compile time
Register 100 jobs 76,320 B, 15.36× the time of one call — none at runtime
Single dispatch — indistinguishable from an empty method indistinguishable from an empty method

What you pay for is [Job] itself: declarative retries, cron and store-backed persistence, not dispatch speed. Full methodology: docs/performance.md.

Learn more

About

Source-generated background job scheduler for .NET 8 and .NET 10. Decorate a class with [Job] and the Roslyn generator wires up the executor, DI registration, and recurring startup — no reflection at runtime.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages