1Take the plain value as the handler's parameter
public static class ShoutJob
{
[Job("shout")]
public static void Handle(string message) => Console.WriteLine(message.ToUpperInvariant());
}2Enqueue it by its generated call
The generated call names the job, and a plain scalar works as its input; no record needed.
var builder = Host.CreateApplicationBuilder(args);
builder.Services.UseActa(j =>
{
j.UseLocalDatabase(builder.Configuration);
j.Run<ScalarInputJobs>("scalar-input");
});
using var host = builder.Build();
await host.StartAsync();
var jobs = host.Services.GetRequiredService<IJobs>();
await jobs.EnqueueAsync(ScalarInputJobs.Shout("durable jobs are simple"));
Console.WriteLine("Enqueued. Worker is running - press Ctrl+C to stop.");
await host.WaitForShutdownAsync();
await host.StopAsync();3Run it and check the output
From a clone of the Acta repository, with the .NET 10 SDK:
dotnet run --project learn/000-fundamentals/005-scalar-inputDURABLE JOBS ARE SIMPLEChecked every release. Before each release, Acta Verify runs this program and checks that its output contains these lines.
This page shows the code. The rules it relies on, starting with the handler running again from its first line, are in the handler contract.
The whole program
Every file of learn/000-fundamentals/005-scalar-input, as it is compiled.
UseLocalDatabase is a helper of the Acta repository, not of the packages. In your own app, register the database with UseSqlite, UsePostgres or UseSqlServer, as in how to run your first job.
scalar-input.cs40 lines
// How to pass one plain value as the input
// The input can be one plain value, such as a string or a number, with no record around it.
using Acta;
using Acta.Learn.ScalarInput;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.UseActa(j =>
{
j.UseLocalDatabase(builder.Configuration);
j.Run<ScalarInputJobs>("scalar-input");
});
using var host = builder.Build();
await host.StartAsync();
var jobs = host.Services.GetRequiredService<IJobs>();
// learn: 2. Enqueue it by its generated call
// The generated call names the job, and a plain scalar works as its input; no record needed.
await jobs.EnqueueAsync(ScalarInputJobs.Shout("durable jobs are simple"));
// learn: end
Console.WriteLine("Enqueued. Worker is running - press Ctrl+C to stop.");
await host.WaitForShutdownAsync();
await host.StopAsync();
namespace Acta.Learn.ScalarInput
{
public static class ShoutJob
{
// learn: 1. Take the plain value as the handler's parameter
[Job("shout")]
public static void Handle(string message) => Console.WriteLine(message.ToUpperInvariant());
// learn: end
}
}