Table of Contents

Class ActivityExecutionContext

Namespace
Temporalio.Activities
Assembly
Temporalio.dll

Context that is available during activity executions. Use Current to get the context. Contexts are AsyncLocal<T> to activities. HasCurrent can be used to check whether a context is available.

public class ActivityExecutionContext
Inheritance
ActivityExecutionContext
Inherited Members

Properties

CancelReason

Gets why the activity was cancelled. This value is inaccurate until CancellationToken is cancelled.

public ActivityCancelReason CancelReason { get; }

Property Value

ActivityCancelReason

CancellationToken

Gets the cancellation token that is cancelled when the activity is cancelled.

public CancellationToken CancellationToken { get; }

Property Value

CancellationToken

Current

Gets the current activity context.

public static ActivityExecutionContext Current { get; }

Property Value

ActivityExecutionContext

Exceptions

InvalidOperationException

If no context is available.

HasCurrent

Gets a value indicating whether the current code is running in an activity.

public static bool HasCurrent { get; }

Property Value

bool

Info

Gets the info for this activity.

public ActivityInfo Info { get; }

Property Value

ActivityInfo

Logger

Gets the logger scoped to this activity.

public ILogger Logger { get; }

Property Value

ILogger

MetricMeter

Gets the metric meter for this activity with activity-specific tags. Note, this is lazily created for each activity execution.

public MetricMeter MetricMeter { get; }

Property Value

MetricMeter

PayloadConverter

Gets the payload converter in use by this activity worker.

public IPayloadConverter PayloadConverter { get; }

Property Value

IPayloadConverter

WorkerShutdownToken

Gets the cancellation token that is cancelled when the worker is shutdown. This can be used to gracefully handle worker shutdown for GracefulShutdownTimeout before CancellationToken will ultimately be cancelled.

public CancellationToken WorkerShutdownToken { get; }

Property Value

CancellationToken

Methods

Heartbeat(params object?[])

Record a heartbeat on the activity.

public void Heartbeat(params object?[] details)

Parameters

details object[]

Details to record with the heartbeat if any.

Remarks

Heartbeats should be used for all non-immediately-returning, non-local activities and they are required to receive cancellation. Heartbeats are queued and processed asynchronously, so this will not error if the details cannot be converted. Rather any error converting heartbeat details will result in activity cancellation then activity failure.

Heartbeat calls are throttled internally based on the heartbeat timeout of the activity. Users do not have to be concerned with burdening the server by calling this too frequently.