WJb Docs - Intermediate

Learn workflows, persistence, scheduling, and production-ready patterns.

πŸš€ Start Here
🧩 Mental Model
🌊 Building Workflows
πŸ’₯ Failures & Control
πŸ‘€ Observation & Debugging
πŸ›  Practical Patterns
βœ… Working Examples
➑️ What’s Next

πŸ“§ Send Email β†’ Log β†’ Done

A complete sequential workflow example.

send-email
    ↓
log
    ↓
Complete

1. Input Models

public sealed class EmailInput
{
    public string To { get; init; } = string.Empty;
    public string Subject { get; init; } = string.Empty;
    public string Body { get; init; } = string.Empty;
}

public sealed class LogInput { public string Message { get; init; } = string.Empty; }


2. Actions

[ActionName("send-email")]
public sealed class SendEmailAction : JobAction<EmailInput>
{
    public override async Task<IActionResult> ExecuteAsync(
        EmailInput input, CancellationToken ct)
    {
        // Simulate sending email
        Console.WriteLine($"Sending email to {input.To}: {input.Subject}");

return await NextAsync<LogAction>( new LogInput { Message = $"Email sent to {input.To}" }); } }

[ActionName("log")] public sealed class LogAction : JobAction<LogInput> { public override async Task<IActionResult> ExecuteAsync( LogInput input, CancellationToken ct) { Console.WriteLine($"LOG: {input.Message}");

return await CompleteAsync(); } }


3. Registration

var wjb = WJbBuilder.Create(store, cfg =>
{
    cfg.AddAction<SendEmailAction>();
    cfg.AddAction<LogAction>();
});

4. Starting the Workflow

await wjb.EnqueueAsync("send-email",
    new EmailInput
    {
        To = "user@example.com",
        Subject = "Welcome",
        Body = "Thank you for joining us!"
    });

5. Execution Result

Sending email to user@example.com: Welcome
LOG: Email sent to user@example.com

Job status becomes Completed.


Key Point

This is the classic sequential pattern:

  • First action does the work and schedules the next step
  • Second action finishes the workflow with Complete
Everything is visible in ordinary C# code.

An unhandled error has occurred. Reload πŸ—™

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.