Skip to content

DurableTaskContext Methods

Describes a running durable task and supplies its host's services.

CreateAttemptCanceledException(Exception?)

View source
protected internal DurableTaskAttemptCanceledException CreateAttemptCanceledException(Exception? innerException)
Creates the exception which this canceled attempt's durable operations throw.

Parameters

innerExceptionException?
The exception which the canceled operation threw, if any.

Exceptions

System.InvalidOperationException
The attempt hasn't been canceled.

GetVersion(string, int, int)

virtual
View source
protected internal virtual int GetVersion(string name, int minSupported, int maxSupported)
Returns the version of the change name which this execution follows, deciding and recording it at the execution's first call for the name.

Parameters

namestring
The change's validated name.
minSupportedint
The oldest version which the calling code supports, at least 0.
maxSupportedint
The newest version, at least minSupported.

Returns

The execution's version, from minSupported to maxSupported.

OnBodyCompleted(DurableTaskResponse)

virtual
View source
protected internal virtual void OnBodyCompleted(DurableTaskResponse response)
Receives this execution's terminal response when its body completes, synchronously with the body's final code.

Parameters

responseDurableTaskResponse
The body's terminal response.

PostTask(TaskId, DurableTask, DurableTaskStartOptions)

virtual
View source
protected internal virtual IScheduledTaskHandle PostTask(TaskId taskId, DurableTask taskDefinition, DurableTaskStartOptions options)
Stages the start of taskDefinition under taskId and records it in this execution, synchronously.

Parameters

taskIdTaskId
A child of DurableTaskContext for an attached task, or the root identifier of a DurableTaskStartOptions task.
taskDefinitionDurableTask
The definition to start.
optionsDurableTaskStartOptions
DurableTaskStartOptions or DurableTaskStartOptions.

Returns

A handle through which this execution observes the task.

RequestTaskCancellation(string?)

View source
protected internal void RequestTaskCancellation(string? reason)
Requests durable cancellation of the task which this context runs, carrying reason.

Parameters

reasonstring?
The reason which DurableTaskContext reports, or null for none. The first request determines the reason, so a host which replays a canceled task passes the reason it recorded with the task's cancellation.

RunEffect(TaskId, TState, Func<TState, DurableTaskResponse>)

virtual
View source
protected internal virtual DurableTaskResponse RunEffect<TState>(TaskId effectId, TState state, Func<TState, DurableTaskResponse> effect)
Returns the outcome recorded for the effect effectId, or runs the effect and records its outcome.

Parameters

effectIdTaskId
The effect's identifier, a child of this execution.
stateTState
The state which effect receives.
effectFunc<TState, DurableTaskResponse>
Runs the effect and returns its outcome: its result, or the exception which it threw. It doesn't throw.

Returns

The effect's outcome, which the host recorded.

ScheduleDelayAsync(TaskId, DateTimeOffset, CancellationToken)

abstract
protected internal abstract ValueTask<DurableTaskResponse> ScheduleDelayAsync(TaskId taskId, DateTimeOffset dueTime, CancellationToken cancellationToken)
Schedules a durable delay at dueTime.

Parameters

taskIdTaskId
dueTimeDateTimeOffset
cancellationTokenCancellationToken

SelectCompletionAsync(TaskId, IReadOnlyList<TaskId>, CancellationToken)

abstract
protected internal abstract ValueTask<TaskId> SelectCompletionAsync(TaskId decisionId, IReadOnlyList<TaskId> candidates, CancellationToken cancellationToken)
Returns a completed candidate, and returns the same candidate for every call with the same decisionId, including calls during replay.

Parameters

decisionIdTaskId
candidatesIReadOnlyList<TaskId>
cancellationTokenCancellationToken

StartTaskAsync(TaskId, DurableTask, DurableTaskStartOptions, CancellationToken)

abstract
protected internal abstract ValueTask<IScheduledTaskHandle> StartTaskAsync(TaskId taskId, DurableTask taskDefinition, DurableTaskStartOptions options, CancellationToken cancellationToken)
Starts, or reattaches to, taskDefinition under taskId, and records the start in this execution.

Parameters

taskIdTaskId
A child of DurableTaskContext for an attached task, or the root identifier of a DurableTaskStartOptions task.
taskDefinitionDurableTask
The definition to start.
optionsDurableTaskStartOptions
How the task relates to this execution, and when the start completes.
cancellationTokenCancellationToken
A token which abandons the start. It doesn't cancel the task.

Returns

A handle through which this execution observes the task.

TryGetCurrent(DurableTaskContext?)

static
View source
public static bool TryGetCurrent(out DurableTaskContext? context)
Gets the context of the durable task which the calling code runs in, if any.

Parameters

contextDurableTaskContext?
The running task's context, or null outside a durable task.

Returns

true when the calling code runs in a durable task.

WaitForSignalAsync(string, CancellationToken)

virtual
View source
protected internal virtual ValueTask<DurableTaskResponse> WaitForSignalAsync(string name, CancellationToken cancellationToken)
Waits for the signal named name of the invoked task whose execution contains this execution, and returns a successful response holding the signal's recorded value.

Parameters

namestring
cancellationTokenCancellationToken