Jobs.Vector 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Jobs.Vector --version 1.0.0
                    
NuGet\Install-Package Jobs.Vector -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jobs.Vector" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jobs.Vector" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Jobs.Vector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Jobs.Vector --version 1.0.0
                    
#r "nuget: Jobs.Vector, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Jobs.Vector@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Jobs.Vector&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Jobs.Vector&version=1.0.0
                    
Install as a Cake Tool

Jobs.Vector

A lightweight, portable .NET 8 background job queue and worker hosting service built on standard .NET primitives (System.Threading.Channels and BackgroundService).

It processes CPU-intensive and long-running operations asynchronously using bounded channels for backpressure, supports multi-threaded concurrent execution loops, and offers a thread-safe in-memory job status store with configurable time-to-live (TTL) eviction.


Technical Architecture

1. Bounded Backpressure via System.Threading.Channels

BackgroundJobQueue utilizes C# Channels configured in BoundedChannelFullMode.Wait mode. If the queue fills up to its maximum capacity, the enqueuing thread blocks and waits rather than letting the memory heap grow out of control.

2. Spanning Multi-Thread Worker Loops

On application startup, BackgroundJobWorker reads the configured worker count and spawns that number of independent Task execution loops. The workers poll the channel concurrently:

  • A thread-safe dequeue removes the job item.
  • The worker updates the status store to Processing.
  • The delegate closure is executed inside a structured try/catch block.
  • Once finished, the state changes to Completed (or Failed with the exception message).

3. Thread-Safe Status Store with TTL Pruning

InMemoryJobStatusStore uses a ConcurrentDictionary to cache job outcomes. To prevent memory leaks, jobs have an associated TTL retention window:

  • Lazy Eviction: Calling GetStatus(jobId) checks the timestamp; if the job has expired, it is removed immediately.
  • Active Cleanup: JobStatusSweepWorker runs a background task that sweeps the dictionary and removes expired entries every minute.

How to Use

1. Registering the Background Services

Bind configuration options and register workers:

using Jobs.Vector;

// Registers IBackgroundJobQueue, IJobStatusStore, and starts the BackgroundJobWorker & JobStatusSweepWorker
builder.Services.AddBackgroundJobs(builder.Configuration);

Configure via appsettings.json:

{
  "Jobs": {
    "Workers": 2,
    "QueueCapacity": 100,
    "StatusRetention": "00:30:00"
  }
}

2. Enqueuing a Job

Inject IBackgroundJobQueue and enqueue an asynchronous task closure:

using Jobs.Vector;

public class IngestionController
{
    private readonly IBackgroundJobQueue _jobQueue;
    private readonly IJobStatusStore _statusStore;

    public IngestionController(IBackgroundJobQueue jobQueue, IJobStatusStore statusStore)
    {
        _jobQueue = jobQueue;
        _statusStore = statusStore;
    }

    public async Task StartIngestion(string fileId, CancellationToken ct)
    {
        string jobId = Guid.NewGuid().ToString();

        // Enqueue job delegate containing processing task context
        await _jobQueue.EnqueueAsync(async (jobCt) =>
        {
            // Simulated work logic
            await Task.Delay(5000, jobCt);
            _statusStore.SetImportResult(jobId, peopleImported: 42, eventsImported: 99);
        }, jobId, ct);
    }
}

3. Polling Job Status

Query the status store using the unique JobId:

using Jobs.Vector;

public JobStatusSnapshot? GetJobStatus(string jobId)
{
    return _statusStore.GetStatus(jobId);
}

License

Distributed under the PolyForm Noncommercial License 1.0.0. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 197 7/21/2026
1.0.4 112 7/21/2026
1.0.3 115 7/21/2026
1.0.2 120 7/14/2026
1.0.1 114 7/14/2026
1.0.0 400 7/14/2026