-
Notifications
You must be signed in to change notification settings - Fork 58
feat(cli): add a read-only \conductor status\ command #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
300ccb7
1007086
4ccfbde
0846748
5ce75a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1112,6 +1112,71 @@ async def _run_replay() -> None: | |||||
| console.print("\n[dim]Replay stopped.[/dim]") | ||||||
|
|
||||||
|
|
||||||
| @app.command(rich_help_panel="Run & Recover") | ||||||
| def status( | ||||||
| json_output: Annotated[ | ||||||
| bool, | ||||||
| typer.Option( | ||||||
| "--json", | ||||||
| help="Emit machine-readable output instead of a table.", | ||||||
| ), | ||||||
| ] = False, | ||||||
| ) -> None: | ||||||
| """List background workflows without stopping any of them. | ||||||
|
|
||||||
| \b | ||||||
| `conductor stop` also lists running workflows, but it stops one when | ||||||
| exactly one is running -- so the natural "what's running?" reflex is | ||||||
| destructive precisely when there is a single run to lose. This command is | ||||||
| read-only and always safe. | ||||||
|
|
||||||
| The dashboard URL is included because there is otherwise no supported way | ||||||
| to recover it once the launching terminal is gone. | ||||||
|
|
||||||
| \b | ||||||
| Exit codes: | ||||||
| 0 listed successfully (including when nothing is running) | ||||||
|
|
||||||
| \b | ||||||
| Examples: | ||||||
| conductor status | ||||||
| conductor status --json | ||||||
| """ | ||||||
| import json | ||||||
|
|
||||||
| from conductor.cli.pid import scan_pid_files | ||||||
|
|
||||||
| # Deliberately not ``read_pid_files``: that one prunes as it reads, which | ||||||
| # would make the read-only command destructive — the exact trap this | ||||||
| # command exists to give people an alternative to. | ||||||
| running = scan_pid_files() | ||||||
|
|
||||||
| if json_output: | ||||||
| payload = [ | ||||||
| { | ||||||
| "pid": e["pid"], | ||||||
| "port": e["port"], | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
One bad file takes out the listing for every healthy run beside it, which is the failure mode most likely to send someone relaunching. For Skipping bad entries and reporting them (a sibling |
||||||
| "workflow": str(e.get("workflow", "")), | ||||||
| "run_id": e.get("run_id", ""), | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Automation will branch on these and take the else path every time. |
||||||
| "started_at": e.get("started_at", ""), | ||||||
| "log_file": e.get("log_file", ""), | ||||||
| "url": f"http://127.0.0.1:{e['port']}", | ||||||
| } | ||||||
| for e in running | ||||||
| ] | ||||||
| output_console.print_json(json.dumps({"running": payload}), ensure_ascii=True) | ||||||
| return | ||||||
|
|
||||||
| if not running: | ||||||
| console.print("[dim]No background workflows are currently running.[/dim]") | ||||||
| return | ||||||
|
|
||||||
| _print_running_list(running, console, show_url=True) | ||||||
| console.print( | ||||||
| f"\n[dim]{len(running)} running. Use 'conductor stop --port <PORT>' to stop one.[/dim]" | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @app.command(rich_help_panel="Run & Recover") | ||||||
| def stop( | ||||||
| port: Annotated[ | ||||||
|
|
@@ -1229,12 +1294,16 @@ def _stop_process(entry: dict, con: Console) -> None: | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def _print_running_list(entries: list[dict], con: Console) -> None: | ||||||
| def _print_running_list(entries: list[dict], con: Console, show_url: bool = False) -> None: | ||||||
| """Print a table of running background workflows. | ||||||
|
|
||||||
| Args: | ||||||
| entries: List of PID-file dicts. | ||||||
| con: Rich Console for output. | ||||||
| show_url: Append a Dashboard URL column. Defaults to False; | ||||||
| ``conductor status`` passes True, since discovery is its whole | ||||||
| purpose and the URL is otherwise unrecoverable once the launching | ||||||
| terminal is gone. | ||||||
| """ | ||||||
| from rich.table import Table | ||||||
|
|
||||||
|
|
@@ -1243,14 +1312,19 @@ def _print_running_list(entries: list[dict], con: Console) -> None: | |||||
| table.add_column("PID", style="yellow") | ||||||
| table.add_column("Workflow", style="white") | ||||||
| table.add_column("Started", style="dim") | ||||||
| if show_url: | ||||||
| table.add_column("Dashboard", style="blue") | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URL gets cropped at the default terminal width. Production So the field the command exists to surface is the one that disappears.
Suggested change
|
||||||
|
|
||||||
| for e in entries: | ||||||
| table.add_row( | ||||||
| row = [ | ||||||
| str(e["port"]), | ||||||
| str(e["pid"]), | ||||||
| Path(e.get("workflow", "unknown")).stem, | ||||||
| e.get("started_at", "?"), | ||||||
| ) | ||||||
| ] | ||||||
| if show_url: | ||||||
| row.append(f"http://127.0.0.1:{e['port']}") | ||||||
| table.add_row(*row) | ||||||
|
|
||||||
| con.print(table) | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the sentence a user leans on to decide whether running the command is safe, and it is not accurate.
read_pid_files()unlinks PID files on three paths (pid.py:150,:155,:164). Since Typer renders this as--help, the claim ships as product copy.