Skip to main content

AsyncFunctionTaskTemplate

A task template that wraps an asynchronous functions. This is automatically created when an asynchronous function is decorated with the task decorator.

Attributes

AttributeTypeDescription
funcFThis attribute stores the asynchronous function that the task template wraps, which is executed when the task is invoked.
plugin_configOptional[Any] = NoneThis attribute is used to pass plugin specific configuration to the task, influencing how the task interacts with various plugins.
debuggablebool = TrueThis attribute indicates whether the task is debuggable, affecting how the task can be inspected or stepped through during execution.
task_resolverOptional[Any] = NoneThis 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

TypeDescription
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

TypeDescription
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

NameTypeDescription
argsP.argsPositional arguments to pass to the wrapped function.
kwargsP.kwargsKeyword arguments to pass to the wrapped function.

Returns

TypeDescription
`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

NameTypeDescription
argsP.argsPositional arguments to pass to the wrapped function.
kwargsP.kwargsKeyword arguments to pass to the wrapped function.

Returns

TypeDescription
RThe 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

NameTypeDescription
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

TypeDescription
List[str]A list of strings representing the command-line arguments for the container.