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
taskQueuestringTask queue which is included in the options name.
buildIdstringBuild ID which is included in the options name.
optionsMonitorIOptionsMonitor<TemporalWorkerServiceOptions>Used to lookup the options to build the worker with.
existingClientITemporalClientExisting client to use if the options don't specify client connection options (connected when run if lazy and not connected).
loggerFactoryILoggerFactoryLogger 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.
[Obsolete("Deprecated older form of DI constructor, TemporalWorkerServiceIdentifier one is used instead.")]
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.
optionsMonitorIOptionsMonitor<TemporalWorkerServiceOptions>Used to lookup the options to build the worker with.
existingClientITemporalClientExisting client to use if the options don't specify client connection options (connected when run if lazy and not connected).
loggerFactoryILoggerFactoryLogger 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
clientITemporalClientClient to use. If this client is lazy and not connected, it will be connected when this service is run.
workerOptionsTemporalWorkerOptionsOptions 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
clientOptionsTemporalClientConnectOptionsOptions to connect a client.
workerOptionsTemporalWorkerOptionsOptions for the worker.
TemporalWorkerService(TemporalWorkerServiceIdentifier, 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(TemporalWorkerServiceIdentifier serviceId, IOptionsMonitor<TemporalWorkerServiceOptions> optionsMonitor, ITemporalClient? existingClient = null, ILoggerFactory? loggerFactory = null)
Parameters
serviceIdTemporalWorkerServiceIdentifierUnique identifier for the Worker service.
optionsMonitorIOptionsMonitor<TemporalWorkerServiceOptions>Used to lookup the options to build the worker with.
existingClientITemporalClientExisting client to use if the options don't specify client connection options (connected when run if lazy and not connected).
loggerFactoryILoggerFactoryLogger 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(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
optionsTemporalWorkerServiceOptionsOptions 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
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.