Table of Contents

Class TemporalWorkerService

Namespace
Temporalio.Extensions.Hosting
Assembly
Temporalio.Extensions.Hosting.dll

Temporal worker implementation as a BackgroundService.

public class TemporalWorkerService : BackgroundService, IHostedService, IDisposable
Inheritance
TemporalWorkerService
Implements
Inherited Members

Constructors

TemporalWorkerService(string, string?, IOptionsMonitor<TemporalWorkerServiceOptions>, ITemporalClient?, ILoggerFactory?)

Initializes a new instance of the TemporalWorkerService class using options and possibly an existing client. This constructor was used by DI containers and is now DEPRECATED.

[Obsolete("Deprecated older form of DI constructor, task queue + build ID tuple one is used instead.")]
public TemporalWorkerService(string taskQueue, string? buildId, IOptionsMonitor<TemporalWorkerServiceOptions> optionsMonitor, ITemporalClient? existingClient = null, ILoggerFactory? loggerFactory = null)

Parameters

taskQueue string

Task queue which is included in the options name.

buildId string

Build ID which is included in the options name.

optionsMonitor IOptionsMonitor<TemporalWorkerServiceOptions>

Used to lookup the options to build the worker with.

existingClient ITemporalClient

Existing client to use if the options don't specify client connection options (connected when run if lazy and not connected).

loggerFactory ILoggerFactory

Logger factory to use if not already on the worker options. The worker options logger factory or this one will be also be used for the client if an existing client does not exist (regardless of client options' logger factory).

TemporalWorkerService((string TaskQueue, string? BuildId), IOptionsMonitor<TemporalWorkerServiceOptions>, ITemporalClient?, ILoggerFactory?)

Initializes a new instance of the TemporalWorkerService class using options and possibly an existing client. This constructor is only for use by DI containers. The task queue and build ID are used as the name for the options monitor to lookup the options for the worker service.

[ActivatorUtilitiesConstructor]
public TemporalWorkerService((string TaskQueue, string? BuildId) taskQueueAndBuildId, IOptionsMonitor<TemporalWorkerServiceOptions> optionsMonitor, ITemporalClient? existingClient = null, ILoggerFactory? loggerFactory = null)

Parameters

taskQueueAndBuildId (string TaskQueue, string BuildId)

Task queue and build ID for the options name.

optionsMonitor IOptionsMonitor<TemporalWorkerServiceOptions>

Used to lookup the options to build the worker with.

existingClient ITemporalClient

Existing client to use if the options don't specify client connection options (connected when run if lazy and not connected).

loggerFactory ILoggerFactory

Logger factory to use if not already on the worker options. The worker options logger factory or this one will be also be used for the client if an existing client does not exist (regardless of client options' logger factory).

Remarks

WARNING: Do not rely on the signature of this constructor, it is for DI container use only and may change in incompatible ways.

TemporalWorkerService(ITemporalClient, TemporalWorkerOptions)

Initializes a new instance of the TemporalWorkerService class using an existing client and worker options.

public TemporalWorkerService(ITemporalClient client, TemporalWorkerOptions workerOptions)

Parameters

client ITemporalClient

Client to use. If this client is lazy and not connected, it will be connected when this service is run.

workerOptions TemporalWorkerOptions

Options for the worker.

TemporalWorkerService(TemporalClientConnectOptions, TemporalWorkerOptions)

Initializes a new instance of the TemporalWorkerService class using client options and worker options. This will create a client on worker start. To provide a client, use TemporalWorkerService(ITemporalClient, TemporalWorkerOptions).

public TemporalWorkerService(TemporalClientConnectOptions clientOptions, TemporalWorkerOptions workerOptions)

Parameters

clientOptions TemporalClientConnectOptions

Options to connect a client.

workerOptions TemporalWorkerOptions

Options for the worker.

TemporalWorkerService(TemporalWorkerServiceOptions)

Initializes a new instance of the TemporalWorkerService class using service options. This will create a client on worker start and therefore ClientOptions must be non-null. To provide a client, use TemporalWorkerService(ITemporalClient, TemporalWorkerOptions).

public TemporalWorkerService(TemporalWorkerServiceOptions options)

Parameters

options TemporalWorkerServiceOptions

Options to use to create the worker service.

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.