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

πŸ’₯ Failure + Retry Example

This example shows how a job fails and is automatically retried.

Attempt 1 β†’ Fail
    ↓ (delay)
Attempt 2 β†’ Fail
    ↓ (delay)
Attempt 3 β†’ Success β†’ Complete

1. Input Model

public sealed class UnstableInput
{
    public string Value { get; init; } = string.Empty;
}

2. Action That Sometimes Fails

[ActionName("unstable-work")]
public sealed class UnstableWorkAction : JobAction<UnstableInput>
{
    private static int _attempt = 0;

public override async Task<IActionResult> ExecuteAsync( UnstableInput input, CancellationToken ct) { _attempt++;

Console.WriteLine($"Attempt {_attempt}: processing '{input.Value}'");

// Fail the first two attempts if (_attempt < 3) { throw new InvalidOperationException( $"Transient error on attempt {_attempt}"); }

Console.WriteLine("Work succeeded"); return await CompleteAsync(); } }


3. Registration

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

4. Enqueue with Retry Options

var options = new JobOptions
{
    // Configure according to the actual API of your WJb version
    // Example shape:
    // MaxRetries = 5,
    // RetryDelay = TimeSpan.FromSeconds(2)
};

await wjb.EnqueueAsync( "unstable-work", new UnstableInput { Value = "important-data" }, options);


5. Expected Behavior

Attempt 1: processing 'important-data'
β†’ throws β†’ job scheduled for retry

Attempt 2: processing 'important-data' β†’ throws β†’ job scheduled for retry

Attempt 3: processing 'important-data' Work succeeded β†’ job Completed


Notes

  • The same payload is reused on every retry
  • The action does not contain retry logic β€” it just throws
  • Retry policy is controlled by JobOptions
  • After the maximum number of attempts the job stays in the Failed state

Key Point

Failures are signaled by exceptions. Retries are declared when the job is enqueued.

This keeps the action clean and the retry behavior configurable.

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.