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
π Conditional Transitions
Actions decide the next step at runtime using ordinary C# control flow.
There is no special routing language or configuration.
Simple Conditional Next
public override async Task<IActionResult> ExecuteAsync(
OrderInput input, CancellationToken ct)
{
if (input.IsPremium)
{
return await NextAsync<PremiumProcessingAction>(
new PremiumInput { OrderId = input.OrderId });
}
return await NextAsync<StandardProcessingAction>(
new StandardInput { OrderId = input.OrderId });
}
The decision is visible directly in the code.
Multiple Conditions
public override async Task<IActionResult> ExecuteAsync(
PaymentInput input,
CancellationToken ct)
{
if (input.Status == "Paid")
{
return await NextAsync<FulfillOrderAction>(...);
}
if (input.Status == "Failed")
{
return await NextAsync<NotifyFailureAction>(...);
}
// default path
return await NextAsync<ReviewPaymentAction>(...);
}
Conditional Fan-out
You can also decide how many next jobs to create:
var commands = new List<JobCommand>();
commands.Add(
JobCommands.Next<LogAction>(
new LogInput { Message = "Order processed" }));
if (input.SendEmail)
{
commands.Add(
JobCommands.Next<SendEmailAction>(
new EmailInput { To = input.Email }));
}
if (input.CreateAudit)
{
commands.Add(
JobCommands.Next<AuditAction>(
new AuditInput { Event = "order" }));
}
return Results.Next(commands.ToArray());
Combining with Complete
Sometimes one branch ends the workflow:
if (input.ShouldStop)
{
return await CompleteAsync();
}
return await NextAsync<ContinueAction>(...);
Using JobCommand Conditions (Optional)
For success/failure based routing you can also use command conditions:
return Results.Next(
JobCommands.Next<SuccessAction>(payload), // runs on success
JobCommands.OnFailure<FailureAction>(errorPayload) // runs on failure
);
Most of the time ordinary if statements are clearer and sufficient.
Best Practices
- Keep conditions simple and readable
- Prefer early returns for clarity
- Avoid deeply nested logic inside a single action
- Extract complex decision logic into a separate method or service if needed
Key Point
Conditional transitions are just normal C# code.
The action evaluates the data and explicitly chooses which job (or jobs) should run next.