flytekit.core.python_customized_container_task
Directory
Classes
| Class | Description |
|---|---|
PythonCustomizedContainerTask |
Please take a look at the comments for flytekit.extend.ExecutableTemplateShimTask as well. |
TaskTemplateResolver |
This is a special resolver that resolves the task above at execution time, using only the TaskTemplate,. |
Variables
| Property | Type | Description |
|---|---|---|
TC |
TypeVar |
|
default_task_template_resolver |
TaskTemplateResolver |
flytekit.core.python_customized_container_task.PythonCustomizedContainerTask
Please take a look at the comments for flytekit.extend.ExecutableTemplateShimTask as well. This class
should be subclassed and a custom Executor provided as a default to this parent class constructor
when building a new external-container flytekit-only plugin.
This class provides authors of new task types the basic scaffolding to create task-template based tasks. In order to write such a task, authors need to
- subclass the
ShimTaskExecutorclass and override theexecute_from_modelfunction. This function is where all the business logic should go. Keep in mind though that you, the plugin author, will not have access to anything that’s not serialized within theTaskTemplatewhich is why you’ll also need to - subclass this class, and override the
get_customfunction to include all the information the executor will need to run. - Also pass the executor you created as the
executor_typeargument of this class’s constructor.
Keep in mind that the total size of the TaskTemplate still needs to be small, since these will be accessed
frequently by the Flyte engine.
class PythonCustomizedContainerTask(
name: str,
task_config: TC,
container_image: str,
executor_type: Type[ShimTaskExecutor],
task_resolver: Optional[TaskTemplateResolver],
task_type,
requests: Optional[Resources],
limits: Optional[Resources],
environment: Optional[Dict[str, str]],
secret_requests: Optional[List[Secret]],
kwargs,
)| Parameter | Type |
|---|---|
name |
str |
task_config |
TC |
container_image |
str |
executor_type |
Type[ShimTaskExecutor] |
task_resolver |
Optional[TaskTemplateResolver] |
task_type |
|
requests |
Optional[Resources] |
limits |
Optional[Resources] |
environment |
Optional[Dict[str, str]] |
secret_requests |
Optional[List[Secret]] |
kwargs |
**kwargs |
Methods
| Method | Description |
|---|---|
compile() |
Generates a node that encapsulates this task in a workflow definition. |
construct_node_metadata() |
Used when constructing the node that encapsulates this task as part of a broader workflow definition. |
dispatch_execute() |
This function is largely similar to the base PythonTask, with the exception that we have to infer the Python. |
execute() |
Rather than running here, send everything to the executor. |
find_lhs() |
|
get_command() |
|
get_config() |
Returns the task config as a serializable dictionary. |
get_container() |
Returns the container definition (if any) that is used to run the task on hosted Flyte. |
get_custom() |
Return additional plugin-specific custom data (if any) as a serializable dictionary. |
get_extended_resources() |
Returns the extended resources to allocate to the task on hosted Flyte. |
get_image() |
|
get_input_types() |
Returns the names and python types as a dictionary for the inputs of this task. |
get_k8s_pod() |
Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte. |
get_sql() |
Returns the Sql definition (if any) that is used to run the task on hosted Flyte. |
get_type_for_input_var() |
Returns the python type for an input variable by name. |
get_type_for_output_var() |
Returns the python type for the specified output variable by name. |
local_execute() |
This function is used only in the local execution path and is responsible for calling dispatch execute. |
local_execution_mode() |
|
post_execute() |
This function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask. |
pre_execute() |
This function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask. |
sandbox_execute() |
Call dispatch_execute, in the context of a local sandbox execution. |
serialize_to_model() |
compile()
def compile(
ctx: flytekit.core.context_manager.FlyteContext,
args,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, NoneType]Generates a node that encapsulates this task in a workflow definition.
| Parameter | Type |
|---|---|
ctx |
flytekit.core.context_manager.FlyteContext |
args |
*args |
kwargs |
**kwargs |
construct_node_metadata()
def construct_node_metadata()Used when constructing the node that encapsulates this task as part of a broader workflow definition.
dispatch_execute()
def dispatch_execute(
ctx: FlyteContext,
input_literal_map: _literal_models.LiteralMap,
) -> Union[_literal_models.LiteralMap, _dynamic_job.DynamicJobSpec]This function is largely similar to the base PythonTask, with the exception that we have to infer the Python
interface before executing. Also, we refer to self.task_template rather than just self similar to task
classes that derive from the base PythonTask.
| Parameter | Type |
|---|---|
ctx |
FlyteContext |
input_literal_map |
_literal_models.LiteralMap |
execute()
def execute(
kwargs,
) -> AnyRather than running here, send everything to the executor.
| Parameter | Type |
|---|---|
kwargs |
**kwargs |
find_lhs()
def find_lhs()get_command()
def get_command(
settings: SerializationSettings,
) -> List[str]| Parameter | Type |
|---|---|
settings |
SerializationSettings |
get_config()
def get_config(
settings: SerializationSettings,
) -> Dict[str, str]Returns the task config as a serializable dictionary. This task config consists of metadata about the custom defined for this task.
| Parameter | Type |
|---|---|
settings |
SerializationSettings |
get_container()
def get_container(
settings: SerializationSettings,
) -> _task_model.ContainerReturns the container definition (if any) that is used to run the task on hosted Flyte.
| Parameter | Type |
|---|---|
settings |
SerializationSettings |
get_custom()
def get_custom(
settings: SerializationSettings,
) -> Dict[str, Any]Return additional plugin-specific custom data (if any) as a serializable dictionary.
| Parameter | Type |
|---|---|
settings |
SerializationSettings |
get_extended_resources()
def get_extended_resources(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[flyteidl.core.tasks_pb2.ExtendedResources]Returns the extended resources to allocate to the task on hosted Flyte.
| Parameter | Type |
|---|---|
settings |
flytekit.configuration.SerializationSettings |
get_image()
def get_image(
settings: SerializationSettings,
) -> str| Parameter | Type |
|---|---|
settings |
SerializationSettings |
get_input_types()
def get_input_types()Returns the names and python types as a dictionary for the inputs of this task.
get_k8s_pod()
def get_k8s_pod(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[flytekit.models.task.K8sPod]Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.
| Parameter | Type |
|---|---|
settings |
flytekit.configuration.SerializationSettings |
get_sql()
def get_sql(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[flytekit.models.task.Sql]Returns the Sql definition (if any) that is used to run the task on hosted Flyte.
| Parameter | Type |
|---|---|
settings |
flytekit.configuration.SerializationSettings |
get_type_for_input_var()
def get_type_for_input_var(
k: str,
v: typing.Any,
) -> typing.Type[typing.Any]Returns the python type for an input variable by name.
| Parameter | Type |
|---|---|
k |
str |
v |
typing.Any |
get_type_for_output_var()
def get_type_for_output_var(
k: str,
v: typing.Any,
) -> typing.Type[typing.Any]Returns the python type for the specified output variable by name.
| Parameter | Type |
|---|---|
k |
str |
v |
typing.Any |
local_execute()
def local_execute(
ctx: flytekit.core.context_manager.FlyteContext,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, typing.Coroutine, NoneType]This function is used only in the local execution path and is responsible for calling dispatch execute. Use this function when calling a task with native values (or Promises containing Flyte literals derived from Python native values).
| Parameter | Type |
|---|---|
ctx |
flytekit.core.context_manager.FlyteContext |
kwargs |
**kwargs |
local_execution_mode()
def local_execution_mode()post_execute()
def post_execute(
_: Optional[ExecutionParameters],
rval: Any,
) -> AnyThis function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask.
| Parameter | Type |
|---|---|
_ |
Optional[ExecutionParameters] |
rval |
Any |
pre_execute()
def pre_execute(
user_params: Optional[ExecutionParameters],
) -> Optional[ExecutionParameters]This function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask.
| Parameter | Type |
|---|---|
user_params |
Optional[ExecutionParameters] |
sandbox_execute()
def sandbox_execute(
ctx: flytekit.core.context_manager.FlyteContext,
input_literal_map: flytekit.models.literals.LiteralMap,
) -> flytekit.models.literals.LiteralMapCall dispatch_execute, in the context of a local sandbox execution. Not invoked during runtime.
| Parameter | Type |
|---|---|
ctx |
flytekit.core.context_manager.FlyteContext |
input_literal_map |
flytekit.models.literals.LiteralMap |
serialize_to_model()
def serialize_to_model(
settings: SerializationSettings,
) -> _task_model.TaskTemplate| Parameter | Type |
|---|---|
settings |
SerializationSettings |
Properties
| Property | Type | Description |
|---|---|---|
container_image |
||
deck_fields |
If not empty, this task will output deck html file for the specified decks |
|
disable_deck |
If true, this task will not output deck html file |
|
docs |
||
enable_deck |
If true, this task will output deck html file |
|
environment |
Any environment variables that supplied during the execution of the task. |
|
executor |
||
executor_type |
||
instantiated_in |
||
interface |
||
lhs |
||
location |
||
metadata |
||
name |
Return the name of the underlying task. |
|
python_interface |
Returns this task’s python interface. |
|
resources |
||
security_context |
||
task_config |
Returns the user-specified task config which is used for plugin-specific handling of the task. |
|
task_resolver |
||
task_template |
Override the base class implementation to serialize on first call. |
|
task_type |
||
task_type_version |
flytekit.core.python_customized_container_task.TaskTemplateResolver
This is a special resolver that resolves the task above at execution time, using only the TaskTemplate,
meaning it should only be used for tasks that contain all pertinent information within the template itself.
This class differs from some TaskResolverMixin pattern a bit. Most of the other resolvers you’ll find,
- restores the same task when
load_taskis called as the object thatloader_argswas called on. That is, even though at run time it’s in a container on a cluster and is obviously a different Python process, the Python object in memory should look the same. - offers a one-to-one mapping between the list of strings returned by the
loader_argsfunction, an the task, at least within the container.
This resolver differs in that,
- when loading a task, the task that is a loaded is always an
ExecutableTemplateShimTask, regardless of what kind of task it was originally. It will only ever have what’s available to it from theTaskTemplate. No information that wasn’t serialized into the template will be available. - all tasks will result in the same list of strings for a given subclass of the
ShimTaskExecutorexecutor. The strings will be["{{.taskTemplatePath}}", "path.to.your.executor"]
Also, get_all_tasks will always return an empty list, at least for now.
def TaskTemplateResolver()Methods
| Method | Description |
|---|---|
find_lhs() |
|
get_all_tasks() |
Future proof method. |
load_task() |
Given the set of identifier keys, should return one Python Task or raise an error if not found. |
loader_args() |
Return a list of strings that can help identify the parameter Task. |
name() |
|
task_name() |
Overridable function that can optionally return a custom name for a given task. |
find_lhs()
def find_lhs()get_all_tasks()
def get_all_tasks()Future proof method. Just making it easy to access all tasks (Not required today as we auto register them)
load_task()
def load_task(
loader_args: List[str],
) -> ExecutableTemplateShimTaskGiven the set of identifier keys, should return one Python Task or raise an error if not found
| Parameter | Type |
|---|---|
loader_args |
List[str] |
loader_args()
def loader_args(
settings: SerializationSettings,
t: PythonCustomizedContainerTask,
) -> List[str]Return a list of strings that can help identify the parameter Task
| Parameter | Type |
|---|---|
settings |
SerializationSettings |
t |
PythonCustomizedContainerTask |
name()
def name()task_name()
def task_name(
t: flytekit.core.base_task.Task,
) -> typing.Optional[str]Overridable function that can optionally return a custom name for a given task
| Parameter | Type |
|---|---|
t |
flytekit.core.base_task.Task |
Properties
| Property | Type | Description |
|---|---|---|
instantiated_in |
||
lhs |
||
location |