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.

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.