Skip to content

Commit 7f4a4c3

Browse files
committed
Update status to return all running vec-inf job status if no job ID is provided
1 parent 7097ced commit 7f4a4c3

File tree

2 files changed

+74
-9
lines changed

2 files changed

+74
-9
lines changed

vec_inf/cli/_cli.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
BatchLaunchResponseFormatter,
3131
LaunchResponseFormatter,
3232
ListCmdDisplay,
33+
ListStatusDisplay,
3334
MetricsResponseFormatter,
3435
StatusResponseFormatter,
3536
)
@@ -313,14 +314,14 @@ def batch_launch(
313314
raise click.ClickException(f"Batch launch failed: {str(e)}") from e
314315

315316

316-
@cli.command("status", help="Check the status of a running model on the cluster.")
317-
@click.argument("slurm_job_id", type=str, nargs=1)
317+
@cli.command("status", help="Check the status of running vec-inf jobs on the cluster.")
318+
@click.argument("slurm_job_id", required=False)
318319
@click.option(
319320
"--json-mode",
320321
is_flag=True,
321322
help="Output in JSON string",
322323
)
323-
def status(slurm_job_id: str, json_mode: bool = False) -> None:
324+
def status(slurm_job_id: str = None, json_mode: bool = False) -> None:
324325
"""Get the status of a running model on the cluster.
325326
326327
Parameters
@@ -338,14 +339,28 @@ def status(slurm_job_id: str, json_mode: bool = False) -> None:
338339
try:
339340
# Start the client and get model inference server status
340341
client = VecInfClient()
341-
status_response = client.get_status(slurm_job_id)
342+
if not slurm_job_id:
343+
slurm_job_ids = client.fetch_running_jobs()
344+
if not slurm_job_ids:
345+
click.echo("No running jobs found.")
346+
return
347+
else:
348+
slurm_job_ids = [slurm_job_id]
349+
responses = []
350+
for job_id in slurm_job_ids:
351+
responses.append(client.get_status(job_id))
352+
342353
# Display status information
343-
status_formatter = StatusResponseFormatter(status_response)
344-
if json_mode:
345-
status_formatter.output_json()
354+
if slurm_job_id:
355+
status_formatter = StatusResponseFormatter(responses[0])
356+
if json_mode:
357+
status_formatter.output_json()
358+
else:
359+
status_info_table = status_formatter.output_table()
360+
CONSOLE.print(status_info_table)
346361
else:
347-
status_info_table = status_formatter.output_table()
348-
CONSOLE.print(status_info_table)
362+
list_status_display = ListStatusDisplay(slurm_job_ids, responses, json_mode)
363+
list_status_display.display_multiple_status_output(CONSOLE)
349364

350365
except click.ClickException as e:
351366
raise e

vec_inf/cli/_helper.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,56 @@ def output_table(self) -> Table:
251251
return table
252252

253253

254+
class ListStatusDisplay:
255+
"""CLI Helper class for formatting a list of StatusResponse.
256+
257+
A formatter class that handles the presentation of multiple job statuses
258+
in a table format.
259+
260+
Parameters
261+
----------
262+
statuses : list[StatusResponse]
263+
List of model status information
264+
"""
265+
266+
def __init__(self, job_ids: list[str], statuses: list[StatusResponse], json_mode: bool = False):
267+
self.job_ids = job_ids
268+
self.statuses = statuses
269+
self.json_mode = json_mode
270+
271+
self.table = Table(show_header=True,header_style="bold magenta")
272+
self.table.add_column("Job ID")
273+
self.table.add_column("Model Name")
274+
self.table.add_column("Status", style="blue")
275+
self.table.add_column("Base URL")
276+
277+
def display_multiple_status_output(self, console: Console) -> None:
278+
"""Format and display all model statuses.
279+
280+
Formats each model's status and adds it to the table.
281+
"""
282+
if self.json_mode:
283+
json_data = [
284+
{
285+
"job_id": status.model_name,
286+
"model_name": status.model_name,
287+
"model_status": status.server_status,
288+
"base_url": status.base_url,
289+
}
290+
for status in self.statuses
291+
]
292+
click.echo(json.dumps(json_data, indent=4))
293+
return
294+
295+
for i, status in enumerate(self.statuses):
296+
self.table.add_row(
297+
self.job_ids[i],
298+
status.model_name,
299+
status.server_status,
300+
status.base_url,
301+
)
302+
console.print(self.table)
303+
254304
class MetricsResponseFormatter:
255305
"""CLI Helper class for formatting MetricsResponse.
256306

0 commit comments

Comments
 (0)