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.