UKBatch.Core 0.2.2-alpha

This is a prerelease version of UKBatch.Core.
dotnet add package UKBatch.Core --version 0.2.2-alpha
                    
NuGet\Install-Package UKBatch.Core -Version 0.2.2-alpha
                    
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="UKBatch.Core" Version="0.2.2-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UKBatch.Core" Version="0.2.2-alpha" />
                    
Directory.Packages.props
<PackageReference Include="UKBatch.Core" />
                    
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 UKBatch.Core --version 0.2.2-alpha
                    
#r "nuget: UKBatch.Core, 0.2.2-alpha"
                    
#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 UKBatch.Core@0.2.2-alpha
                    
#: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=UKBatch.Core&version=0.2.2-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=UKBatch.Core&version=0.2.2-alpha&prerelease
                    
Install as a Cake Tool

UKBatch.Core

The runtime for UKBatch — a lightweight, pluggable batch/job orchestration library for .NET 8 and .NET 10. This package contains the dispatcher, the cron scheduler, the job/batch executors, the in-memory stores, and the in-process transport. It is everything you need to run jobs inside a single process; adapter packages swap in persistence and cross-service transport without code changes.

Status: part of the UKBatch 0.1.0-alpha package family.

Install

dotnet add package UKBatch.Core

Quick start

In a console or generic-host application, register the runtime with AddUKBatch and describe your jobs and batches in the builder:

using UKBatch;

services.AddUKBatch(b =>
{
    // A single job, addressed by an explicit name.
    b.AddJob<MyJob>().Named("MyJob");

    // A sequential batch: StepA, then StepB.
    b.AddBatch("pipeline", x => x
        .RunJob<StepA>()
        .ThenRunJob<StepB>());

    // Or discover [Job]-decorated types by scanning assemblies:
    // b.ScanAssemblies(typeof(Program).Assembly);
});

MyJob, StepA, and StepB are classes implementing IJob (from UKBatch.Abstractions). Resolve IJobRunner from DI to trigger a job or batch at runtime.

Defaults

Out of the box AddUKBatch wires the in-memory store and the in-process transport — no extra calls are required to get running. Swap either by adding an adapter package: UKBatch.Storage.EntityFrameworkCore for PostgreSQL/SQLite persistence, UKBatch.Transport.Http or UKBatch.Transport.RabbitMQ for cross-service messaging. The same job and batch code keeps working; only where state lives and how services talk changes.

Workflows

Batches compose real patterns, all expressed through the fluent builder:

  • SequentialRunJob<A>().ThenRunJob<B>().
  • Parallel fan-out / fan-inThenInParallel(p => p.RunJob<A>().RunJob<B>().JoinPolicy(ParallelJoinPolicy.WaitAll)).
  • Approval gateThenWaitForApproval(title: "Confirm", roles: ["ops"], timeout: TimeSpan.FromMinutes(30), onTimeout: ApprovalTimeoutAction.Hold) pauses the batch until a human approves or rejects.
  • CompensationOnFailure(f => f.RunJob<Rollback>()).FailurePolicy(BatchFailurePolicy.Compensate).

Partitioned jobs

For data-parallel work — "fetch a set of items, then process them on N workers" — implement IPartitionedJob<TItem>. The runtime owns the producer/consumer plumbing (a bounded channel plus N consumer tasks); you declare only the source stream and the per-item work:

using UKBatch.Abstractions.Jobs;

public sealed class ReconcileInvoicesJob : IPartitionedJob<int>
{
    // Stream the items to process. Yield lazily so the bounded channel applies backpressure.
    public async IAsyncEnumerable<int> SourceAsync(JobContext context, CancellationToken ct)
    {
        context.Progress.SetTotal(100);          // drives a live x/100 progress counter
        for (var id = 1; id <= 100; id++)
            yield return id;
    }

    // Runs on N concurrent workers — MUST be thread-safe.
    public Task ProcessAsync(int id, JobContext context, CancellationToken ct) =>
        ReconcileAsync(id, ct);

    // Optional commit hook: runs exactly once after every item, single-threaded.
    // Skipped on a fail-fast abort or cancellation; under ContinueOnError it commits the subset that succeeded.
    public Task FinalizeAsync(JobContext context, CancellationToken ct) =>
        SaveResultsAsync(ct);
}

Register it with a worker count and a per-item error policy:

b.AddPartitionedJob<ReconcileInvoicesJob, int>()
    .Named("ReconcileInvoices")
    .WithParallelism(4)
    .WithItemErrorPolicy(ItemErrorPolicy.ContinueOnError);

The worker count can be overridden per run by passing the trigger parameter ukbatch.workers (an invalid value falls back to the configured parallelism with a warning, and the effective count is capped at 128).

When to use it

  • ASP.NET Core apps should reference UKBatch.AspNetCore instead — it depends on this package and adds host integration, HttpContext-aware trigger enrichment, and a readiness health check.
  • Plain hosts and console apps reference UKBatch.Core directly and register with services.AddUKBatch(...).

License

MIT. See LICENSE in the repo root. Full docs: nspukcode-hub.github.io/UKBatch · GitHub.

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 is compatible.  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 (6)

Showing the top 5 NuGet packages that depend on UKBatch.Core:

Package Downloads
UKBatch.AspNetCore

ASP.NET Core integration for UKBatch — HttpContext-aware TriggeredBy enrichment, W3C trace propagation, and a readiness IHealthCheck. Use AddUKBatchAspNetCore on IServiceCollection or WebApplicationBuilder.

UKBatch.Api

REST API + OpenAPI 3.1 schema + SignalR push hub for UKBatch. Mounts under any RouteGroupBuilder via MapUKBatchApi. Auth-agnostic — call RequireAuthorization to opt in.

UKBatch.Transport.RabbitMQ

RabbitMQ (AMQP) transport adapter for UKBatch — cross-service ITransport over a broker with durable/persistent messaging, publisher confirms, manual ack, dead-letter queue and request/reply (direct-reply-to). Plug-in replacement for InProcessTransport / HttpTransport when microservices need to communicate over a broker. Security at the broker layer (user/pass + TLS); no application-level HMAC.

UKBatch.Worker

Worker-mode helper for UKBatch (Server + Workers deployment). One call — builder.UseWorkerMode(...) — turns a microservice into a worker that advertises itself to the UKBatch.Server over an HTTP heartbeat (observability only) and fail-fasts at startup unless a cross-service ITransport (RabbitMQ/HTTP) is registered. Adds NOTHING to the dispatch path; the orchestrator reaches the worker over the transport. References Abstractions + Core only — never UKBatch.Api.

UKBatch.Storage.EntityFrameworkCore

EF Core 10 persistent storage adapter for UKBatch — IJobStore + IBatchDefinitionStore + durable approval gates over PostgreSQL (Npgsql) and SQLite. Plug-in replacement for the in-memory stores so batch definitions, execution history, and pending approvals survive host restarts.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2-alpha 84 6/18/2026
0.2.1-alpha 80 6/15/2026
0.2.0-alpha 85 6/14/2026
0.1.6-alpha 84 6/13/2026
0.1.5-alpha 85 6/12/2026
0.1.4-alpha 86 6/10/2026
0.1.3-alpha 84 6/8/2026
0.1.1-alpha 85 6/8/2026
0.1.0-alpha 87 6/6/2026