ContainerTask
This is an intermediate class that represents Flyte Tasks that run a container at execution time. This is the vast majority of tasks - the typical @task decorated tasks; for instance, all run a container. An example of something that doesn't run a container would be something like the Athena SQL task.
Attributes
| Attribute | Type | Description |
|---|---|---|
| MetadataFormat | Literal["JSON", "YAML", "PROTO"] | The format of the output file. This can be "JSON", "YAML", or "PROTO". |
| local_logs | bool = True | If True, logs will be printed to the console in the local execution. |
Constructor
Signature
def ContainerTask(
name: str,
image: Union[str, [Image](../../image/image.md?sid=flyte__image_image)],
command: List[str],
inputs: Optional[Dict[str, Type]] = None,
arguments: Optional[List[str]] = None,
outputs: Optional[Dict[str, Type]] = None,
input_data_dir: str | pathlib.Path = "/var/inputs",
output_data_dir: str | pathlib.Path = "/var/outputs",
metadata_format: MetadataFormat = "JSON",
local_logs: bool = True,
block_network: bool = False
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Name of the task |
| image | Union[str, [Image](../../image/image.md?sid=flyte__image_image)] | The container image to use for the task. |
| command | List[str] | The command to run in the container. |
| inputs | Optional[Dict[str, Type]] = None | The inputs to the task as a dictionary of names to types. |
| arguments | Optional[List[str]] = None | The arguments to pass to the command. |
| outputs | Optional[Dict[str, Type]] = None | The outputs of the task as a dictionary of names to types. |
| input_data_dir | `str | pathlib.Path` = "/var/inputs" |
| output_data_dir | `str | pathlib.Path` = "/var/outputs" |
| metadata_format | MetadataFormat = "JSON" | The format of the output file (JSON, YAML, or PROTO). |
| local_logs | bool = True | If True, logs will be printed to the console in local execution. |
| block_network | bool = False | If True, blocks all outbound network access. |
Methods
execute()
@classmethod
def execute(
kwargs: Any
) - > Any
Executes the task locally by running a Docker container with the specified image, commands, and volume mounts.
Parameters
| Name | Type | Description |
|---|---|---|
| kwargs | Any | The input values provided to the task for execution. |
Returns
| Type | Description |
|---|---|
Any | The processed outputs of the task execution. |
data_loading_config()
@classmethod
def data_loading_config(
sctx: [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > tasks_pb2.DataLoadingConfig
Generates the data loading configuration for the task, specifying input/output paths and metadata formats for the Flyte engine.
Parameters
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The context used during the serialization of the task. |
Returns
| Type | Description |
|---|---|
tasks_pb2.DataLoadingConfig | A protobuf message containing the data loading specifications. |
container_args()
@classmethod
def container_args(
sctx: [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > List[str]
Constructs the full list of arguments to be passed to the container by combining the base command and additional arguments.
Parameters
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The context used during the serialization of the task. |
Returns
| Type | Description |
|---|---|
List[str] | A list of strings representing the complete command and arguments for the container. |