Anarchy.Toolkit.Hosting.Workers
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Hosting · Package catalog
Background-worker primitives and a self-hosted health API for worker processes.
dotnet add package Anarchy.Toolkit.Hosting.Workers
- Derive from
WorkerBase,MonitoredWorkerBaseorResilientWorkerBase;HeartbeatWorkerprovides a heartbeat. ResilientWorkerBasegives every iteration a new correlation id and every attempt a new attempt id, throughCorrelationContext.BeginScope: they reach every logging provider as scope properties and the current activity as tags. Work that carries its own ids (a consumed message) opensBeginCorrelationScope(correlationId, attemptId)around its processing.- Register the health worker with
AddServiceHealthCheckWorker(assembly)to serve/health/instance,/health/servicesand/health/status. - Supply an
IReadOnlyCollection<IHealthCheck>for service checks; the services endpoint returns HTTP 500 when a check fails.
When to use it
Choose this package for a long-running process that needs hosted workers, operational heartbeat or HTTP health endpoints without building a full REST API. It complements Hosting, which provides the application host and entry-point conventions.
How to use it
- Implement a worker using the base that matches the required monitoring or resilience behavior, and register it with the host’s
IServiceCollectionas a hosted service. Instrumented workers take the registeredAppTelemetry(seeModuleTelemetryorAddCoreTelemetry()). - If health endpoints are required, call
services.AddServiceHealthCheckWorker(typeof(YourWorker).Assembly)from startup. Register settings implementingIWorkerHealthCheckAppSettings, including the health service port, and make the listener reachable only as appropriate for your deployment. - Supply the
IReadOnlyCollection<IHealthCheck>used by the endpoint, or use a provider’s health-report registration. Without reports, the package installs an empty collection. Embed build metadata in the supplied assembly if it should appear in status output.
The sample worker startup demonstrates registering a heartbeat and a custom hosted worker.
See the worker sample and toolkit overview.
Releases
See the release notes for the complete release history.