Acta. Durable execution for .NET

learn actastart jobs

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.

A how-to for Acta, durable execution for .NET. New to Acta? Run your first durable job in five minutes.

Checked every release learn/000-fundamentals/005-scalar-input
Read as

1Take the plain value as the handler's parameter

scalar-input.csexcerpt
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.

scalar-input.csexcerpt
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:

Terminal
dotnet run --project learn/000-fundamentals/005-scalar-input
Its output must contain
DURABLE JOBS ARE SIMPLE

Checked 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
scalar-input.cs
// 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
    }
}

Where to go next

New to Acta?

Acta is durable execution for .NET: workflows and jobs that survive restarts, as a library inside your application with its durable state in your SQL database.