AsyncFunctionTaskTemplate
A task template that wraps an asynchronous functions. This is automatically created when an asynchronous function is decorated with the task decorator.
Attributes
| Attribute | Type | Description |
|---|
| func | F | This attribute stores the asynchronous function that the task template wraps, which is executed when the task is invoked. |
| plugin_config | Optional[Any] = None | This attribute is used to pass plugin specific configuration to the task, influencing how the task interacts with various plugins. |
| debuggable | bool = True | This attribute indicates whether the task is debuggable, affecting how the task can be inspected or stepped through during execution. |
| task_resolver | Optional[Any] = None | This attribute stores an optional task resolver, which is used to locate and load the task's code during serialization and execution. |
Methods
source_file()
@classmethod
def source_file() - > Optional[str]
Returns the source file of the function, if available. This is useful for debugging and tracing.
Returns
| Type | Description |
|---|
Optional[str] | The file path of the source code for the wrapped function, or None if not available. |
json_schema()
@classmethod
def json_schema() - > Dict[str, Any]
JSON schema for the task inputs, following the Flyte standard. Delegates to NativeInterface.json_schema, which uses the type engine to produce a LiteralType per input and converts to JSON schema.
Returns
| Type | Description |
|---|
Dict[str, Any] | A dictionary representing the JSON schema for the task's inputs. |
forward()
@classmethod
def forward(
args: P.args,
kwargs: P.kwargs
) - > Coroutine[Any, Any, R]| R
Calls the wrapped function directly. In local execution, this method is used to invoke the function, returning a coroutine if the function is asynchronous, which the caller is expected to await.
Parameters
| Name | Type | Description |
|---|
| args | P.args | Positional arguments to pass to the wrapped function. |
| kwargs | P.kwargs | Keyword arguments to pass to the wrapped function. |
Returns
| Type | Description |
|---|
| `Coroutine[Any, Any, R] | R` |
execute()
@classmethod
def execute(
args: P.args,
kwargs: P.kwargs
) - > R
Executes the wrapped function, handling both synchronous and asynchronous functions within an asynchronous context. This method manages the task context and calls pre- and post-execution hooks.
Parameters
| Name | Type | Description |
|---|
| args | P.args | Positional arguments to pass to the wrapped function. |
| kwargs | P.kwargs | Keyword arguments to pass to the wrapped function. |
Returns
| Type | Description |
|---|
R | The result of the wrapped function's execution. |
container_args()
@classmethod
def container_args(
serialize_context: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > List[str]
Builds a list of command-line arguments for the container execution of the task. This includes paths for inputs, outputs, versioning, and potentially code bundle information or a task resolver.
Parameters
| Name | Type | Description |
|---|
| serialize_context | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The context containing information needed for serialization, such as input/output paths, version, and code bundle details. |
Returns
| Type | Description |
|---|
List[str] | A list of strings representing the command-line arguments for the container. |