Table of Contents

Class TemporalWorkerOptions

Namespace
Temporalio.Worker
Assembly
Temporalio.dll

Options for a TemporalWorker. TaskQueue and at least one workflow or activity are required. Most users will use AddActivity(Delegate) and/or AddWorkflow<T>() to add activities and workflows.

public class TemporalWorkerOptions : ICloneable
Inheritance
TemporalWorkerOptions
Implements
Derived
Inherited Members

Constructors

TemporalWorkerOptions()

Initializes a new instance of the TemporalWorkerOptions class.

public TemporalWorkerOptions()

TemporalWorkerOptions(string)

Initializes a new instance of the TemporalWorkerOptions class.

public TemporalWorkerOptions(string taskQueue)

Parameters

taskQueue string

Task queue for the worker.

Properties

Activities

Gets the activity definitions. Most users will use AddActivity to add to this list.

public IList<ActivityDefinition> Activities { get; }

Property Value

IList<ActivityDefinition>

ActivityTaskFactory

Gets or sets the task queue for activities. Default is Factory.

public TaskFactory ActivityTaskFactory { get; set; }

Property Value

TaskFactory

BuildId

Gets or sets the build ID. This is a unique identifier for each "build" of the worker. If unset, the default is Assembly.GetEntryAssembly().ManifestModule.ModuleVersionId.

public string? BuildId { get; set; }

Property Value

string

DebugMode

Gets or sets a value indicating whether deadlock detection will be disabled for all workflows. If unset, this value defaults to true only if IsAttached is true or the TEMPORAL_DEBUG environment variable is true or 1.

public bool DebugMode { get; set; }

Property Value

bool

Remarks

When false, the default, deadlock detection prevents workflow tasks from taking too long before yielding back to Temporal. This is undesirable when stepping through code, so this should be set to true in those cases.

DefaultHeartbeatThrottleInterval

Gets or sets the default interval for throttling activity heartbeats in case per-activity heartbeat timeout is unset. Otherwise, it's the per-activity heartbeat timeout * 0.8. Default is 30s.

public TimeSpan DefaultHeartbeatThrottleInterval { get; set; }

Property Value

TimeSpan

DisableWorkflowTracingEventListener

Gets or sets a value indicating whether workflow tracing event listener will be disabled for all workflows.

public bool DisableWorkflowTracingEventListener { get; set; }

Property Value

bool

Remarks

When false, the default, a EventListener is used to catch improper calls from inside the workflow.

GracefulShutdownTimeout

Gets or sets the amount of time after shutdown is called that activities are given to complete before they are cancelled.

public TimeSpan GracefulShutdownTimeout { get; set; }

Property Value

TimeSpan

Identity

Gets or sets the identity for this worker. If unset, defaults to the client's identity.

public string? Identity { get; set; }

Property Value

string

Interceptors

Gets or sets the interceptors. Note this automatically includes any Interceptors that implement IWorkerInterceptor so those should not be specified here. This set is chained after the set in the client options.

public IReadOnlyCollection<IWorkerInterceptor>? Interceptors { get; set; }

Property Value

IReadOnlyCollection<IWorkerInterceptor>

LocalActivityWorkerOnly

Gets or sets a value indicating whether the worker will only handle workflows and local activities.

public bool LocalActivityWorkerOnly { get; set; }

Property Value

bool

LoggerFactory

Gets or sets the logging factory used by loggers in workers. If unset, defaults to the client logger factory.

public ILoggerFactory? LoggerFactory { get; set; }

Property Value

ILoggerFactory

MaxActivitiesPerSecond

Gets or sets the limit for the number of activities per second that this worker will process. The worker will not poll for new activities if by doing so it might receive and execute an activity which would cause it to exceed this limit.

public double? MaxActivitiesPerSecond { get; set; }

Property Value

double?

MaxCachedWorkflows

Gets or sets the number of workflows cached for sticky task queue use. If this is 0, sticky task queues are disabled and no caching occurs. Default is 10000.

public int MaxCachedWorkflows { get; set; }

Property Value

int

MaxConcurrentActivities

Gets or sets the maximum number of activities that will ever be given to this worker concurrently. Default is 100. Mutually exclusive with Tuner.

public int? MaxConcurrentActivities { get; set; }

Property Value

int?

MaxConcurrentActivityTaskPolls

Gets or sets the maximum number of concurrent poll activity task requests we will perform at a time on this worker's task queue. Default is 5.

public int MaxConcurrentActivityTaskPolls { get; set; }

Property Value

int

MaxConcurrentLocalActivities

Gets or sets the maximum number of local activities that will ever be given to this worker concurrently. Default is 100. Mutually exclusive with Tuner.

public int? MaxConcurrentLocalActivities { get; set; }

Property Value

int?

MaxConcurrentWorkflowTaskPolls

Gets or sets the maximum number of concurrent poll workflow task requests we will perform at a time on this worker's task queue. Default is 5.

public int MaxConcurrentWorkflowTaskPolls { get; set; }

Property Value

int

MaxConcurrentWorkflowTasks

Gets or sets the maximum allowed number of workflow tasks that will ever be given to the worker at one time. Default is 100. Mutually exclusive with Tuner.

public int? MaxConcurrentWorkflowTasks { get; set; }

Property Value

int?

MaxHeartbeatThrottleInterval

Gets or sets the longest interval for throttling activity heartbeats. Default is 60s.

public TimeSpan MaxHeartbeatThrottleInterval { get; set; }

Property Value

TimeSpan

MaxTaskQueueActivitiesPerSecond

Gets or sets the maximum number of activities per second the task queue will dispatch, controlled server-side. Note that this only takes effect upon an activity poll request. If multiple workers on the same queue have different values set, they will thrash with the last poller winning.

public double? MaxTaskQueueActivitiesPerSecond { get; set; }

Property Value

double?

NonStickyToStickyPollRatio

Gets or sets the sticky poll ratio. MaxConcurrentWorkflowTaskPolls times this value will be the number of max pollers that will be allowed for the non-sticky queue when sticky tasks are enabled. If both defaults are used, the sticky queue will allow 4 max pollers while the non-sticky queue will allow 1. The minimum for either poller is 1, so if MaxConcurrentWorkflowTaskPolls is 1 and sticky queues are enabled, there will be 2 concurrent polls. Default is 0.2.

public float NonStickyToStickyPollRatio { get; set; }

Property Value

float

StickyQueueScheduleToStartTimeout

Gets or sets how long a workflow task is allowed to sit on the sticky queue before it is timed out and moved to the non-sticky queue where it may be picked up by any worker. Default is 10s.

public TimeSpan StickyQueueScheduleToStartTimeout { get; set; }

Property Value

TimeSpan

TaskQueue

Gets or sets the task queue for the worker.

public string? TaskQueue { get; set; }

Property Value

string

Tuner

public WorkerTuner? Tuner { get; set; }

Property Value

WorkerTuner

Remarks

WARNING: WorkerTuners are experimental.

UseWorkerVersioning

Gets or sets a value indicating whether this worker opts into the worker versioning feature. This ensures it only receives workflow tasks for workflows which it claims to be compatible with. The BuildId field is used as this worker's version when enabled, and must be set.

public bool UseWorkerVersioning { get; set; }

Property Value

bool

WorkflowFailureExceptionTypes

Gets or sets the types of exceptions that, if a workflow-thrown exception extends, will cause the workflow/update to fail instead of suspending the workflow via task failure. These are applied in addition to FailureExceptionTypes on a specific workflow. If typeof(Exception) is set, it effectively will fail a workflow/update in all user exception cases.

public IReadOnlyCollection<Type>? WorkflowFailureExceptionTypes { get; set; }

Property Value

IReadOnlyCollection<Type>

Remarks

WARNING: This property is experimental and may change in the future. If unset (i.e. left null), currently the default is to only fail the workflow/update on FailureException + cancellation and suspend via task failure all others. But this default may change in the future.

WorkflowStackTrace

Gets or sets the form of workflow stack trace queries are supported. Default is "None" which means workflow stack trace are not supported and will fail.

public WorkflowStackTrace WorkflowStackTrace { get; set; }

Property Value

WorkflowStackTrace

Remarks

Currently due to internal implementation details, stack traces have to be captured eagerly on every Temporal task creation that can be waited on. Due to this performance cost, they are turned off by default.

Workflows

Gets the workflow definitions. Most users will use AddWorkflow to add to this list.

public IList<WorkflowDefinition> Workflows { get; }

Property Value

IList<WorkflowDefinition>

Methods

AddActivity(Delegate)

Add the given delegate with ActivityAttribute as an activity. This is usually a method reference.

public TemporalWorkerOptions AddActivity(Delegate del)

Parameters

del Delegate

Delegate to add.

Returns

TemporalWorkerOptions

This options instance for chaining.

AddActivity(ActivityDefinition)

Add the given activity definition. Most users will use AddActivity(Delegate) instead.

public TemporalWorkerOptions AddActivity(ActivityDefinition definition)

Parameters

definition ActivityDefinition

Definition to add.

Returns

TemporalWorkerOptions

This options instance for chaining.

AddAllActivities(Type, object?)

Add all methods on the given type with ActivityAttribute.

public TemporalWorkerOptions AddAllActivities(Type type, object? instance)

Parameters

type Type

Type to get activities from.

instance object

Instance to use when invoking. This must be non-null if any activities are non-static.

Returns

TemporalWorkerOptions

This options instance for chaining.

AddAllActivities<T>(T?)

Add all methods on the given type with ActivityAttribute.

public TemporalWorkerOptions AddAllActivities<T>(T? instance)

Parameters

instance T

Instance to use when invoking. This must be non-null if any activities are non-static.

Returns

TemporalWorkerOptions

This options instance for chaining.

Type Parameters

T

Type to get activities from.

AddWorkflow(Type)

Add the given type as a workflow.

public TemporalWorkerOptions AddWorkflow(Type type)

Parameters

type Type

Type to add.

Returns

TemporalWorkerOptions

This options instance for chaining.

AddWorkflow(WorkflowDefinition)

Add the given workflow definition. Most users will use AddWorkflow<T>() instead.

public TemporalWorkerOptions AddWorkflow(WorkflowDefinition definition)

Parameters

definition WorkflowDefinition

Definition to add.

Returns

TemporalWorkerOptions

This options instance for chaining.

AddWorkflow<T>()

Add the given type as a workflow.

public TemporalWorkerOptions AddWorkflow<T>()

Returns

TemporalWorkerOptions

This options instance for chaining.

Type Parameters

T

Type to add.

Clone()

Create a shallow copy of these options.

public virtual object Clone()

Returns

object

A shallow copy of these options and any transitive options fields. Also copies collections of activities and workflows.

Events

WorkflowTaskCompleted

Event for when a workflow task has completed but not yet sent back to the server. This should only be used for very advanced scenarios.

public event EventHandler<WorkflowTaskCompletedEventArgs>? WorkflowTaskCompleted

Event Type

EventHandler<WorkflowTaskCompletedEventArgs>

Remarks

WARNING: This is experimental and there are many caveats about its use. It is important to read the documentation on WorkflowTaskStarting.

WorkflowTaskStarting

Event for when a workflow task is starting. This should only be used for very advanced scenarios.

public event EventHandler<WorkflowTaskStartingEventArgs>? WorkflowTaskStarting

Event Type

EventHandler<WorkflowTaskStartingEventArgs>

Remarks

WARNING: This is experimental and may change in the future.