WorkerOptions

Read time 2 minutes Package: Nalix.Framework
On this page

Namespace: Nalix.Framework.Options
Assembly: Nalix.Framework

WorkerOptions (public sealed class WorkerOptions : IWorkerOptions) configures per-worker scheduling priority, group concurrency gating, post-completion retention, OS thread priority, and CPU core affinity in TaskManager.ScheduleWorker.

Source Mapping

  • src/Nalix.Abstractions/Concurrency/IWorkerOptions.cs
  • src/Nalix.Framework/Options/WorkerOptions.cs
  • src/Nalix.Framework/Tasks/TaskManager.Affinity.cs

Public Properties

PropertyTypeAccessDefaultDescription
Tagstring?get; set;nullOptional diagnostic tag for grouping or filtering the worker in reports.
MachineIdushortget; set;110-bit machine ID embedded in the worker’s ISnowflake identifier.
IdTypeSnowflakeTypeget; set;SnowflakeType.SystemSnowflakeType embedded in the worker’s ISnowflake identifier.
PriorityWorkerPriorityget; set;WorkerPriority.NORMALQueue priority (LOW, NORMAL, HIGH, URGENT) when waiting for a concurrency slot.
ExecutionTimeoutTimeSpan?get;nullOptional execution timeout budget (read via IWorkerOptions.ExecutionTimeout).
RetainForTimeSpan?get; set;2 min (TimeSpan.FromMinutes(2))Duration finished workers remain in TaskManager for diagnostic inspection (null or TimeSpan.Zero removes immediately on completion).
GroupConcurrencyLimitint?get; set;nullOptional maximum concurrent workers allowed in the worker’s group.
TryAcquireSlotImmediatelyboolget; set;falseWhen true, cancels the worker immediately if a group/global slot is not available instead of queuing.
CancellationTokenCancellationTokenget; set;CancellationToken.NoneExternal cancellation token linked into the worker’s internal CancellationTokenSource.
OnCompletedAction<IWorkerHandle>?get; set;nullCallback invoked when the worker finishes without throwing an exception.
OnFailedAction<IWorkerHandle, Exception>?get; set;nullCallback invoked when the worker faults with an unhandled exception.
OSPriorityThreadPriority?get; set;nullOptional OS thread priority. When set, TaskManager runs the worker on a dedicated thread instead of the ThreadPool.
ProcessorAffinityint?get; set;nullOptional 0-based CPU core index for thread affinity (applied on Windows and Linux when OSPriority is also set).

Usage Example

using System;
using System.Threading;
using Nalix.Abstractions.Concurrency;
using Nalix.Abstractions.Identity;
using Nalix.Framework.Options;

WorkerOptions options = new()
{
    Tag = "wal-flush",
    MachineId = 1,
    IdType = SnowflakeType.System,
    Priority = WorkerPriority.HIGH,
    GroupConcurrencyLimit = 1,
    TryAcquireSlotImmediately = false,
    RetainFor = TimeSpan.FromMinutes(5),
    OSPriority = ThreadPriority.AboveNormal,
    ProcessorAffinity = 0
};