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
β Complete vs Next
Every action must tell WJb what should happen after it finishes.
There are two primary outcomes:
- Complete β the workflow ends
- Next β one or more new jobs are scheduled
Complete
Use Complete when the current job is the final step.
No result
return await CompleteAsync();
With a result
return Results.Complete(
new { Sent = true, MessageId = "abc-123" });
Scalar values are also supported:
return Results.Complete(42);
return Results.Complete("done");
return Results.Complete(true);
The returned value becomes the job result and is stored.
Next
Use Next when the workflow should continue.
Single next step
return await NextAsync<LogAction>(
new LogInput { Message = "Email sent" });
This creates one new job for LogAction.
Multiple next steps (fan-out)
return Results.Next(
JobCommands.Next<LogAction>(
new LogInput { Message = "Email sent" }),
JobCommands.Next<AuditAction>(
new AuditInput { Event = "email" }));
Both jobs are enqueued and can run independently.
Side-by-Side
| Intention | Return | Effect |
|-------------------------------|---------------------------------|---------------------------------|
| Finish the workflow | CompleteAsync() | Job marked Completed |
| Finish and save a value | Results.Complete(value) | Job Completed + result stored |
| Continue with one action | NextAsync | One new job created |
| Continue with several actions | Results.Next(...) | Multiple new jobs created |
Typical Pattern
public override async Task<IActionResult> ExecuteAsync(
EmailInput input,
CancellationToken ct)
{
// do the work
await SendEmailAsync(input, ct);
// decide what happens next
return await NextAsync<LogAction>(
new LogInput { Message = $"Email sent to {input.To}" });
}
Later, in LogAction:
return await CompleteAsync();
Key Point
Completeends the current branch of the workflow.Nextcreates the continuation.