From 544f299046f0a8a62f5774eb589d2734d7804b0d Mon Sep 17 00:00:00 2001 From: "Jack He (Github)" Date: Wed, 22 Feb 2023 17:11:07 -0800 Subject: [PATCH] Prepend task id if it exists to "ray task list --detail" (#32353) This change addresses this issue: #30805. It solves a UX issue where the "task_id" field isn't printed FIRST. So this change prepends it, which can be shown in the following screenshot: UPDATED screenshot: --- python/ray/experimental/state/state_cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/ray/experimental/state/state_cli.py b/python/ray/experimental/state/state_cli.py index 55f94ad6bc31..26213b61d498 100644 --- a/python/ray/experimental/state/state_cli.py +++ b/python/ray/experimental/state/state_cli.py @@ -27,6 +27,7 @@ StateResource, StateSchema, SupportedFilterType, + TaskState, resource_to_schema, ) from ray.experimental.state.exception import RayStateApiException @@ -282,9 +283,17 @@ def format_get_api_output( schema: StateSchema, format: AvailableFormat = AvailableFormat.YAML, ) -> str: + if not state_data or len(state_data) == 0: return f"Resource with id={id} not found in the cluster." + if schema == TaskState and format == AvailableFormat.YAML: + augmented_task_state_data = [ + {("task_id: " + state["task_id"]): state} for state in state_data + ] + return output_with_format( + augmented_task_state_data, schema=schema, format=format + ) return output_with_format(state_data, schema=schema, format=format) @@ -296,6 +305,13 @@ def format_list_api_output( ) -> str: if len(state_data) == 0: return "No resource in the cluster" + if schema == TaskState and format == AvailableFormat.YAML: + augmented_task_state_data = [ + {("task_id: " + state["task_id"]): state} for state in state_data + ] + return output_with_format( + augmented_task_state_data, schema=schema, format=format + ) return output_with_format(state_data, schema=schema, format=format)