Table of Contents

Class TemporalWorker

Namespace
Temporalio.Worker
Assembly
Temporalio.dll

Worker for running Temporal workflows and/or activities. This intentionally matches Microsoft.Extensions.Hosting.BackgroundService structure.

public class TemporalWorker : IDisposable
Inheritance
TemporalWorker
Implements
Inherited Members

Constructors

TemporalWorker(IWorkerClient, TemporalWorkerOptions)

Initializes a new instance of the TemporalWorker class. The options must have a task queue set and at least one workflow or activity.

public TemporalWorker(IWorkerClient client, TemporalWorkerOptions options)

Parameters

client IWorkerClient

Client for this workflow. This is implemented by the commonly used ITemporalClient.

options TemporalWorkerOptions

Options for the worker.

Properties

Options

Gets the options this worker was created with.

public TemporalWorkerOptions Options { get; }

Property Value

TemporalWorkerOptions

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Dispose the worker.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Whether disposing.

ExecuteAsync(Func<Task>, CancellationToken)

Run this worker until failure, cancelled, or task from given function completes.

public Task ExecuteAsync(Func<Task> untilComplete, CancellationToken stoppingToken = default)

Parameters

untilComplete Func<Task>

If the task returned from this function completes, the worker will shutdown propagating exception as necessary.

stoppingToken CancellationToken

Cancellation token to stop the worker.

Returns

Task

When the task is complete, the worker has completed shutdown.

Remarks

When shutting down, the worker will cancel and wait for completion for all executing activities. If an activity does not properly respond to cancellation, this may never return.

Exceptions

InvalidOperationException

Already started.

OperationCanceledException

Cancellation requested.

Exception

Fatal worker failure.

ExecuteAsync(CancellationToken)

Run this worker until failure or cancelled.

public Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Cancellation token to stop the worker.

Returns

Task

Task that will never succeed, only fail. When the task is complete, the worker has completed shutdown.

Remarks

This intentionally matches Microsoft.Extensions.Hosting.BackgroundService.ExecuteAsync.

When shutting down, the worker will cancel and wait for completion for all executing activities. If an activity does not properly respond to cancellation, this may never return.

Exceptions

InvalidOperationException

Already started.

OperationCanceledException

Cancellation requested.

Exception

Fatal worker failure.

ExecuteAsync<TResult>(Func<Task<TResult>>, CancellationToken)

Run this worker until failure, cancelled, or task from given function completes.

public Task<TResult> ExecuteAsync<TResult>(Func<Task<TResult>> untilComplete, CancellationToken stoppingToken = default)

Parameters

untilComplete Func<Task<TResult>>

If the task returned from this function completes, the worker will shutdown (propagating) exception as necessary.

stoppingToken CancellationToken

Cancellation token to stop the worker.

Returns

Task<TResult>

When the task is complete, the worker has completed shutdown.

Type Parameters

TResult

Result of given function's task.

Remarks

When shutting down, the worker will cancel and wait for completion for all executing activities. If an activity does not properly respond to cancellation, this may never return.

Exceptions

InvalidOperationException

Already started.

OperationCanceledException

Cancellation requested.

Exception

Fatal worker failure.

~TemporalWorker()

Finalizes an instance of the TemporalWorker class.

protected ~TemporalWorker()