Skip to content

Commit

Permalink
Boolean flag to show local container logs to the terminal (flyteorg#2521
Browse files Browse the repository at this point in the history
)

Signed-off-by: aditya7302 <aditya7302@gmail.com>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Co-authored-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
  • Loading branch information
2 people authored and mao3267 committed Aug 2, 2024
1 parent 758736f commit 25381ce
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flytekit/core/container_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
secret_requests: Optional[List[Secret]] = None,
pod_template: Optional["PodTemplate"] = None,
pod_template_name: Optional[str] = None,
local_logs: bool = False,
**kwargs,
):
sec_ctx = None
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(
requests=requests if requests else Resources(), limits=limits if limits else Resources()
)
self.pod_template = pod_template
self.local_logs = local_logs

@property
def resources(self) -> ResourceSpec:
Expand Down Expand Up @@ -249,6 +251,11 @@ def execute(self, **kwargs) -> LiteralMap:
)
# Wait for the container to finish the task
# TODO: Add a 'timeout' parameter to control the max wait time for the container to finish the task.

if self.local_logs:
for log in container.logs(stream=True):
print(f"[Local Container] {log.strip()}")

container.wait()

output_dict = self._get_output_dict(output_directory)
Expand Down

0 comments on commit 25381ce

Please sign in to comment.