TickerQTickerQ
GuidesDefining Jobs

Lambda Handlers

Inline function registration without a class.

Available in version *.3.0 or later.

MapTicker accepts inline lambdas for lightweight jobs that don't need a class.

Simple

Program.cs
builder.Services.MapTicker("log-heartbeat", async (context, ct) =>
{
    Console.WriteLine("Heartbeat");
});

With service provider

Access DI services via IServiceProvider:

Program.cs
builder.Services.MapTicker("notify", async (context, sp, ct) =>
{
    var mailer = sp.GetRequiredService<IMailer>();
    await mailer.SendAsync(ct);
});

With typed request

Program.cs
builder.Services.MapTicker<OrderPayload>("process-order", async (context, ct) =>
{
    var order = context.Request; // OrderPayload
});

// With typed request + service provider
builder.Services.MapTicker<OrderPayload>("process-order", async (context, sp, ct) =>
{
    var repo = sp.GetRequiredService<IOrderRepo>();
    await repo.ProcessAsync(context.Request, ct);
});

Builder options

Lambda registrations also return TickerFunctionBuilder:

Program.cs
builder.Services.MapTicker("cleanup", async (ctx, ct) => { /* ... */ })
    .WithCron("0 0 * * *")
    .WithPriority(TickerTaskPriority.Low);

On this page