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