Add name to task output

This commit is contained in:
Joshua Boniface 2023-11-16 13:23:31 -05:00
parent 0cb81f96e6
commit 9958d1cfe8
2 changed files with 31 additions and 10 deletions

View File

@ -284,7 +284,8 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
task_list_output = [] task_list_output = []
# Determine optimal column widths # Determine optimal column widths
task_id_length = 7 task_id_length = 3
task_name_length = 5
task_type_length = 7 task_type_length = 7
task_worker_length = 7 task_worker_length = 7
task_arg_name_length = 5 task_arg_name_length = 5
@ -296,6 +297,10 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
_task_id_length = len(str(task["id"])) + 1 _task_id_length = len(str(task["id"])) + 1
if _task_id_length > task_id_length: if _task_id_length > task_id_length:
task_id_length = _task_id_length task_id_length = _task_id_length
# task_name column
_task_name_length = len(str(task["name"])) + 1
if _task_name_length > task_name_length:
task_name_length = _task_name_length
# task_worker column # task_worker column
_task_worker_length = len(str(task["worker"])) + 1 _task_worker_length = len(str(task["worker"])) + 1
if _task_worker_length > task_worker_length: if _task_worker_length > task_worker_length:
@ -316,8 +321,8 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
if _task_arg_name_length > task_arg_name_length: if _task_arg_name_length > task_arg_name_length:
task_arg_name_length = _task_arg_name_length task_arg_name_length = _task_arg_name_length
if len(str(arg_data)) > 20: if len(str(arg_data)) > 17:
arg_data = arg_data[:20] + "..." arg_data = arg_data[:17] + "..."
# task_arg_data column # task_arg_data column
_task_arg_data_length = len(str(arg_data)) + 1 _task_arg_data_length = len(str(arg_data)) + 1
@ -334,39 +339,50 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
bold=ansii["bold"], bold=ansii["bold"],
end_bold=ansii["end"], end_bold=ansii["end"],
task_header_length=task_id_length task_header_length=task_id_length
+ task_name_length
+ task_type_length + task_type_length
+ task_worker_length + task_worker_length
+ 2, + 3,
arg_header_length=task_arg_name_length + task_arg_data_length, arg_header_length=task_arg_name_length + task_arg_data_length,
task_header="Tasks " task_header="Tasks "
+ "".join( + "".join(
[ [
"-" "-"
for _ in range( for _ in range(
6, task_id_length + task_type_length + task_worker_length + 1 6,
task_id_length
+ task_name_length
+ task_type_length
+ task_worker_length
+ 2,
) )
] ]
), ),
arg_header="Arguments " arg_header="Arguments "
+ "".join( + "".join(
["-" for _ in range(12, task_arg_name_length + task_arg_data_length)] [
"-"
for _ in range(11, task_arg_name_length + task_arg_data_length + 1)
]
), ),
) )
) )
task_list_output.append( task_list_output.append(
"{bold}{task_id: <{task_id_length}} {task_type: <{task_type_length}} \ "{bold}{task_id: <{task_id_length}} {task_name: <{task_name_length}} {task_type: <{task_type_length}} \
{task_worker: <{task_worker_length}} \ {task_worker: <{task_worker_length}} \
{task_arg_name: <{task_arg_name_length}} \ {task_arg_name: <{task_arg_name_length}} \
{task_arg_data: <{task_arg_data_length}}{end_bold}".format( {task_arg_data: <{task_arg_data_length}}{end_bold}".format(
task_id_length=task_id_length, task_id_length=task_id_length,
task_name_length=task_name_length,
task_type_length=task_type_length, task_type_length=task_type_length,
task_worker_length=task_worker_length, task_worker_length=task_worker_length,
task_arg_name_length=task_arg_name_length, task_arg_name_length=task_arg_name_length,
task_arg_data_length=task_arg_data_length, task_arg_data_length=task_arg_data_length,
bold=ansii["bold"], bold=ansii["bold"],
end_bold=ansii["end"], end_bold=ansii["end"],
task_id="Job ID", task_id="ID",
task_name="Name",
task_type="Status", task_type="Status",
task_worker="Worker", task_worker="Worker",
task_arg_name="Name", task_arg_name="Name",
@ -377,11 +393,12 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
# Format the string (elements) # Format the string (elements)
for task in sorted(tasks, key=lambda i: i.get("type", None)): for task in sorted(tasks, key=lambda i: i.get("type", None)):
task_list_output.append( task_list_output.append(
"{bold}{task_id: <{task_id_length}} {task_type: <{task_type_length}} \ "{bold}{task_id: <{task_id_length}} {task_name: <{task_name_length}} {task_type: <{task_type_length}} \
{task_worker: <{task_worker_length}} \ {task_worker: <{task_worker_length}} \
{task_arg_name: <{task_arg_name_length}} \ {task_arg_name: <{task_arg_name_length}} \
{task_arg_data: <{task_arg_data_length}}{end_bold}".format( {task_arg_data: <{task_arg_data_length}}{end_bold}".format(
task_id_length=task_id_length, task_id_length=task_id_length,
task_name_length=task_name_length,
task_type_length=task_type_length, task_type_length=task_type_length,
task_worker_length=task_worker_length, task_worker_length=task_worker_length,
task_arg_name_length=task_arg_name_length, task_arg_name_length=task_arg_name_length,
@ -389,6 +406,7 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
bold="", bold="",
end_bold="", end_bold="",
task_id=task["id"], task_id=task["id"],
task_name=task["name"],
task_type=task["type"], task_type=task["type"],
task_worker=task["worker"], task_worker=task["worker"],
task_arg_name=str(task["kwargs"][0]["name"]), task_arg_name=str(task["kwargs"][0]["name"]),
@ -397,11 +415,12 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
) )
for arg in task["kwargs"][1:]: for arg in task["kwargs"][1:]:
task_list_output.append( task_list_output.append(
"{bold}{task_id: <{task_id_length}} {task_type: <{task_type_length}} \ "{bold}{task_id: <{task_id_length}} {task_name: <{task_name_length}} {task_type: <{task_type_length}} \
{task_worker: <{task_worker_length}} \ {task_worker: <{task_worker_length}} \
{task_arg_name: <{task_arg_name_length}} \ {task_arg_name: <{task_arg_name_length}} \
{task_arg_data: <{task_arg_data_length}}{end_bold}".format( {task_arg_data: <{task_arg_data_length}}{end_bold}".format(
task_id_length=task_id_length, task_id_length=task_id_length,
task_name_length=task_name_length,
task_type_length=task_type_length, task_type_length=task_type_length,
task_worker_length=task_worker_length, task_worker_length=task_worker_length,
task_arg_name_length=task_arg_name_length, task_arg_name_length=task_arg_name_length,
@ -409,6 +428,7 @@ def cli_cluster_task_format_pretty(CLI_CONFIG, task_data):
bold="", bold="",
end_bold="", end_bold="",
task_id="", task_id="",
task_name="",
task_type="", task_type="",
task_worker="", task_worker="",
task_arg_name=str(arg["name"]), task_arg_name=str(arg["name"]),

View File

@ -267,6 +267,7 @@ def task_status(config, task_id=None, is_watching=False):
task["type"] = task_type task["type"] = task_type
task["worker"] = task_host task["worker"] = task_host
task["id"] = task_job.get("id") task["id"] = task_job.get("id")
task["name"] = task_job.get("name")
try: try:
task["args"] = literal_eval(task_job.get("args")) task["args"] = literal_eval(task_job.get("args"))
except Exception: except Exception: