Build a Priority-Aware Background Job Runner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5175

    #1

    Build a Priority-Aware Background Job Runner

    Build a Priority-Aware Background Job Runner with WJb 0.7.1‑beta1 (Console App, .NET 8/10)


    Goal: A minimal console app that enqueues two jobs and prints:


    Hello Oleksandr!
    Hello World!

    …in that exact order, thanks to priority queues—the High priority job runs before the Normal one.





    Why WJb?

    WJb is a lightweight background job runner for .NET that embraces familiar primitives:
    • Hosted service (BackgroundService)
    • Priority queues using Channel
    • Configurable parallelism
    • DI-friendly actions via IActionFactory
    • Compact job payloads in JSON (code + more)


    In 0.7.1‑beta1, actions initialize from a merged payload (more) and execute with a cancellation token, keeping things clean and testable.





    Project Setup

    Create a new console app (dotnet new console) and add the package:








    Sdk="Microsoft.NET.Sdk">



    Exe
    net10.0
    enable
    enable




    Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />

    Include="Microsoft.Extensions.Hosting" Version="10.0.0" />

    Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />

    Include="WJb" Version="0.7.1-beta1" />



Working...