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
If no job is available, the call returns immediately.

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:

  • CronWorker
  • WasmWorker
  • WasmWorkerPool
(Exact usage depends on the hosting model.)

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.

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.