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
π Execution Control
WJb gives you direct control over how and when jobs are executed.
You decide whether to run a single job, process a queue continuously, or cancel work in progress.
Execute Once
Process a single available job and then stop:
await wjb.ExecuteOnceAsync();
Useful for:
- Testing
- Controlled environments
- Step-by-step debugging
Execute Loop
Run continuously until cancellation is requested:
await wjb.ExecuteLoopAsync(cancellationToken);
The typical production pattern:
while (not cancelled)
{
Dequeue β Execute β Complete/Next
}
This is the most common way to host workers.
Cancellation
You can cancel a running job:
bool cancelled = wjb.TryCancel(jobId);
If the job is currently executing and the action respects the CancellationToken, execution stops.
Always pass the token inside actions:
public override async Task<IActionResult> ExecuteAsync(
MyInput input, CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
await SomeLongOperationAsync(ct);
return await CompleteAsync();
}
Starting and Stopping Workers
Depending on the host you use:
// Example with a worker
worker.Start();
// ...
worker.Stop();
worker.Dispose();
Available worker types include:
CronWorkerWasmWorkerWasmWorkerPool
Queue-Specific Execution (when supported)
Process only jobs from a named queue:
await wjb.ExecuteLoopAsync(queue: "emails");
This allows you to separate workloads (high-priority, background, etc.).
Common Hosting Patterns
Console / Worker Service
await wjb.ExecuteLoopAsync(stoppingToken);
On-demand
await wjb.ExecuteOnceAsync();
Blazor WASM
Use WasmWorker or WasmWorkerPool and call NotifyWorkAvailable() when new jobs are enqueued.
Key Point
Execution is never magical.
You explicitly start the executor, choose once vs loop, and can cancel individual jobs when needed.
The actions remain focused on business logic while you control the runtime behavior.