DurableTaskContext
Namespace: Orleans.Durable.Tasks
public abstract class DurableTaskContextRemarks
Task code reads the running task's context from DurableTask. Hosts derive from this type to schedule and record the task's operations.
An execution's code runs on one scheduler, the one which was current when the host created the context, such as its grain activation's scheduler, so the context's state needs no synchronization. The host creates the context, requests task cancellation, and cancels the attempt on that scheduler, and the execution's code allocates identifiers and runs effects there: an operation which code runs elsewhere, for example after `ConfigureAwait(false)`, throws System.InvalidOperationException. The cancellation tokens and the handles which the execution observes remain safe to use from any thread.
Constructors
DurableTaskContext(TaskId)Initializes an attempt of the durable tasktaskId.
Properties
AttemptCancellationReasonGets why this attempt was canceled, ornullwhile it runs.AttemptCancellationTokenGets the token which is canceled when the host cancels this attempt: its grain activation is stopping, or the task was aborted or deleted. Pass it to the calls which durable cleanup makes after task cancellation.CancellationTokenGets the token which is canceled when durable cancellation of the task is requested or the host cancels this attempt. Pass it to the calls which ordinary task code makes.HostIdGets the identity of the host which runs this execution, such as its grain, which qualifies the root identifiers which the execution derives for the detached tasks it starts, ornullfor none.IdGets this execution's identifier.IncarnationGets the nonce which identifies the run of the root task which this execution belongs to.IsAttemptCanceledGets a value indicating whether this attempt was canceled, by the host or by a divergence of its replay.IsReplayingGets a value indicating whether this run of the task's body is re-running operations which an earlier run recorded. Use it for logging and diagnostics only.IsTaskCancellationRequestedGets a value indicating whether durable cancellation of the task has been requested.SchedulesShieldedChildrenGets whether the calling code runs within aDurableTaskExtensionsstart of this execution, so that a child which it schedules isn't reached by this execution's durable cancellation.TaskCancellationReasonGets the reason which the durable cancellation request carries, ornullwhen task cancellation hasn't been requested or its request carries no reason.UtcNowGets the host-provided logical UTC time for this execution.
Methods
CancelAttempt(DurableTaskAttemptCancellationReason)Cancels this attempt forreason.CreateAttemptCanceledException(Exception?)Creates the exception which this canceled attempt's durable operations throw.GetVersion(string, int, int)Returns the version of the changenamewhich this execution follows, deciding and recording it at the execution's first call for the name.OnBodyCompleted(DurableTaskResponse)Receives this execution's terminal response when its body completes, synchronously with the body's final code.PostTask(TaskId, DurableTask, DurableTaskStartOptions)Stages the start oftaskDefinitionundertaskIdand records it in this execution, synchronously.RequestTaskCancellation(string?)Requests durable cancellation of the task which this context runs, carryingreason.RunEffect(TaskId, TState, Func<TState, DurableTaskResponse>)Returns the outcome recorded for the effecteffectId, or runs the effect and records its outcome.ScheduleDelayAsync(TaskId, DateTimeOffset, CancellationToken)Schedules a durable delay atdueTime.SelectCompletionAsync(TaskId, IReadOnlyList<TaskId>, CancellationToken)Returns a completed candidate, and returns the same candidate for every call with the samedecisionId, including calls during replay.StartTaskAsync(TaskId, DurableTask, DurableTaskStartOptions, CancellationToken)Starts, or reattaches to,taskDefinitionundertaskId, and records the start in this execution.TryGetCurrent(DurableTaskContext?)Gets the context of the durable task which the calling code runs in, if any.WaitForSignalAsync(string, CancellationToken)Waits for the signal namednameof the invoked task whose execution contains this execution, and returns a successful response holding the signal's recorded value.
