Class: Context
activity.Context
Activity Context, used to:
- Get Info about the current Activity Execution
- Send heartbeats
- Get notified of Activity cancellation
- Sleep (cancellation-aware)
Call Context.current()
from Activity code in order to get the current Activity's Context.
Propertiesβ
cancellationSignalβ
β’ Readonly
cancellationSignal: AbortSignal
An AbortSignal
that can be used to react to
Activity cancellation.
Used by fetch to abort an in-progress request and child_process to abort a child process, and is supported by some other libraries as well.
See
cancelledβ
β’ Readonly
cancelled: Promise
<never
>
Await this promise in an Activity to get notified of cancellation.
This promise will never resolveβit will only be rejected with a CancelledFailure.
See
infoβ
β’ info: Info
Holds information about the current executing Activity.
Methodsβ
heartbeatβ
βΈ heartbeat(details?
): void
Send a heartbeat from an Activity.
If an Activity times out, then during the next retry, the last value of details
is available at
heartbeatDetails. This acts as a periodic checkpoint mechanism for the progress of an Activity.
If an Activity times out on the final retry (relevant in cases in which RetryPolicy.maximumAttempts is
set), the Activity function call in the Workflow code will throw an ActivityFailure with the cause
attribute set to a TimeoutFailure, which has the last value of details
available at
TimeoutFailure.lastHeartbeatDetails.
Activities must heartbeat in order to receive cancellation.
Parametersβ
Name | Type |
---|---|
details? | unknown |
Returnsβ
void
sleepβ
βΈ sleep(ms
): Promise
<void
>
Helper function for sleeping in an Activity.
Parametersβ
Name | Type | Description |
---|---|---|
ms | string | number | Sleep duration: an ms-formatted string or number of milliseconds |
Returnsβ
Promise
<void
>
A Promise that either resolves when ms
is reached or rejects when the Activity is cancelled
currentβ
βΈ Static
current(): Context
Gets the context of the current Activity.
Uses AsyncLocalStorage under the hood to make it accessible in nested callbacks and promises.