Functions that can be called inside of activities.
Most of these functions use contextvars
to obtain the current activity
in context. This is already set before the start of the activity. Activities
that make calls that do not automatically propagate the context, such as calls
in another thread, should not use the calls herein unless the context is
explicitly propagated.
Class |
|
Information about the running activity. |
Class |
|
Adapter that adds details to the log about the running activity. |
Function | defn |
Decorator for activity functions. |
Function | heartbeat |
Send a heartbeat for the current activity. |
Function | in |
Whether the current code is inside an activity. |
Function | info |
Current activity's info. |
Function | is |
Whether a cancellation was ever requested on this activity. |
Function | is |
Whether shutdown has been invoked on the worker. |
Function | metric |
Get the metric meter for the current activity. |
Function | payload |
Get the payload converter for the current activity. |
Function | raise |
Raise an error that says the activity will be completed asynchronously. |
Function | shield |
Context manager for synchronous multithreaded activities to delay cancellation exceptions. |
Async Function | wait |
Asynchronously wait for this activity to get a cancellation request. |
Function | wait |
Synchronously block while waiting for a cancellation request on this activity. |
Async Function | wait |
Asynchronously wait for shutdown to be called on the worker. |
Function | wait |
Synchronously block while waiting for shutdown to be called on the worker. |
Variable | logger |
Logger that will have contextual activity details embedded. |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Exception | _ |
Undocumented |
Variable | _current |
Undocumented |
@overload
Optional[ str]
= None, no_thread_cancel_exception: bool
= False) -> Callable[ [ CallableType], CallableType]
:bool
= False, dynamic: bool
= False) -> Callable[ [ CallableType], CallableType]
:Decorator for activity functions.
Activities can be async or non-async.
Parameters | |
fn:Optional[ | The function to decorate. |
name:Optional[ | Name to use for the activity. Defaults to function __name__. This cannot be set if dynamic is set. |
nobool | If set to true, an exception will not be raised in synchronous, threaded activities upon cancellation. |
dynamic:bool | If true, this activity will be dynamic. Dynamic activities have to accept a single 'Sequence[RawValue]' parameter. This cannot be set to true if name is present. |
Current activity's info.
Returns | |
Info | Info for the currently running activity. |
Raises | |
RuntimeError | When not in an activity. |
Whether a cancellation was ever requested on this activity.
Returns | |
bool | True if the activity has had a cancellation request, False otherwise. |
Raises | |
RuntimeError | When not in an activity. |
Whether shutdown has been invoked on the worker.
Returns | |
bool | True if shutdown has been called on the worker, False otherwise. |
Raises | |
RuntimeError | When not in an activity. |
Get the metric meter for the current activity.
Warning
This is only available in async or synchronous threaded activities. An error is raised on non-thread-based sync activities when trying to access this.
Returns | |
temporalio.common.MetricMeter | Current metric meter for this activity for recording metrics. |
Raises | |
RuntimeError | When not in an activity or in a non-thread-based synchronous activity. |
Get the payload converter for the current activity.
This is often used for dynamic activities to convert payloads.
Context manager for synchronous multithreaded activities to delay cancellation exceptions.
By default, synchronous multithreaded activities have an exception thrown inside when cancellation occurs. Code within a "with" block of this context manager will delay that throwing until the end. Even if the block returns a value or throws its own exception, if a cancellation exception is pending, it is thrown instead. Therefore users are encouraged to not throw out of this block and can surround this with a try/except if they wish to catch a cancellation.
This properly supports nested calls and will only throw after the last one.
This just runs the blocks with no extra effects for async activities or synchronous multiprocess/other activities.
Raises | |
temporalio.exceptions.CancelledError | If a cancellation occurs anytime during this block and this is not nested in another shield block. |
Asynchronously wait for this activity to get a cancellation request.
Raises | |
RuntimeError | When not in an async activity. |
Synchronously block while waiting for a cancellation request on this activity.
This is essentially a wrapper around threading.Event.wait
.
Parameters | |
timeout:Optional[ | Max amount of time to wait for cancellation. |
Raises | |
RuntimeError | When not in an activity. |
Asynchronously wait for shutdown to be called on the worker.
Raises | |
RuntimeError | When not in an async activity. |
Synchronously block while waiting for shutdown to be called on the worker.
This is essentially a wrapper around threading.Event.wait
.
Parameters | |
timeout:Optional[ | Max amount of time to wait for shutdown to be called on the worker. |
Raises | |
RuntimeError | When not in an activity. |