Skip to main content

One-off Scheduling

Implementing a Job Handler

To process work, implement the IJobHandler interface. JobMaster resolves dependencies via the DI container, so all services must be registered.

public sealed class HelloJobHandler : IJobHandler
{
public async Task HandleAsync(JobContext job)
{
var name = job.MsgData.TryGetStringValue("Name") ?? "World";
Console.WriteLine($"Hello {name}");
await Task.CompletedTask;
}
}

Scheduling Methods

Use IJobMasterScheduler to enqueue work. Build the message data with WriteableMessageData:

var msg = WriteableMessageData.New()
.SetStringValue("Name", "John Doe")
.SetIntValue("Tries", 1);

Immediate Execution

Enqueues the job to run as soon as a worker is available.

await jobMasterScheduler.OnceNowAsync<HelloJobHandler>(msg);

Specific Time Execution

Schedules the job to run at an exact UTC datetime.

var runAt = DateTime.UtcNow.AddMinutes(5);
await jobMasterScheduler.OnceAtAsync<HelloJobHandler>(runAt, msg);

Delay Execution

Schedules the job to run after a relative time span from now.

await jobMasterScheduler.OnceAfterAsync<HelloJobHandler>(TimeSpan.FromMinutes(5), msg);

Multi-Cluster Support

If your application connects to multiple JobMaster clusters, specify which one to target:

await scheduler.OnceNowAsync<HelloJobHandler>(clusterId: "sales-microservice-cluster");

Next Steps