Enhance logging and timing in CLI and session operations
- Updated the `_print_checks` function to replace console prints with logging functions for better traceability. - Introduced timing functionality in the `doctor`, `dry_run`, and `up` functions to log the duration of preflight checks. - Modified the `wait_ssh` function to accept a logging callback, improving SSH wait feedback. - Enhanced the `mark` method in `PhaseTimes` to log phase durations, aiding in performance analysis. - Updated various remote scripts to ensure error messages are printed to stderr for better error handling.
This commit is contained in:
+18
-5
@@ -61,20 +61,22 @@ def _print_checks(checks, *, quiet: bool = False) -> int:
|
||||
failed = blocking_failed(checks)
|
||||
if quiet:
|
||||
if failed:
|
||||
console.print("[red]doctor: блокирующие проблемы[/red]")
|
||||
err("doctor: блокирующие проблемы")
|
||||
for check in failed:
|
||||
console.print(f" • {check.name}: {check.detail}")
|
||||
log(f" • {check.name}: {check.detail}")
|
||||
_print_next_steps(failed)
|
||||
return 1
|
||||
warns = [c for c in checks if not c.ok and not c.blocking]
|
||||
if warns:
|
||||
console.print(f"[yellow]doctor ok[/yellow] ({len(checks)}), предупреждения:")
|
||||
warn(f"doctor ok ({len(checks)}), предупреждения:")
|
||||
for check in warns:
|
||||
console.print(f" • {check.name}: {check.detail}")
|
||||
log(f" • {check.name}: {check.detail}")
|
||||
else:
|
||||
console.print(f"[green]doctor ok[/green] ({len(checks)} проверок)")
|
||||
ok(f"doctor ok ({len(checks)} проверок)")
|
||||
return 0
|
||||
|
||||
from gpu_rent.timing import clock_prefix
|
||||
|
||||
table = Table(title="gpu-rent doctor", show_lines=False)
|
||||
table.add_column("ok")
|
||||
table.add_column("проверка")
|
||||
@@ -84,6 +86,7 @@ def _print_checks(checks, *, quiet: bool = False) -> int:
|
||||
mark = "[green]yes[/green]" if check.ok else "[red]NO[/red]"
|
||||
block = "да" if check.blocking else "нет"
|
||||
table.add_row(mark, check.name, block, check.detail)
|
||||
console.print(f"[dim]{clock_prefix()}[/dim]таблица doctor ↓")
|
||||
console.print(table)
|
||||
if failed:
|
||||
console.print("\n[red]Сессию начинать нельзя.[/red] См. docs/setup.md")
|
||||
@@ -130,8 +133,12 @@ def version() -> None:
|
||||
def doctor() -> None:
|
||||
"""Preflight без create: Keystone, квота, flavor, диск, Civitai, манифесты."""
|
||||
try:
|
||||
from gpu_rent.timing import clock_reset, format_duration, clock_elapsed
|
||||
|
||||
clock_reset()
|
||||
log("запускаю проверку…")
|
||||
checks = run_doctor()
|
||||
log(f"проверка заняла {format_duration(clock_elapsed())}")
|
||||
except GpuRentError as exc:
|
||||
_die(exc)
|
||||
code = _print_checks(checks)
|
||||
@@ -142,6 +149,9 @@ def doctor() -> None:
|
||||
def dry_run() -> None:
|
||||
"""План без mutating-вызовов."""
|
||||
try:
|
||||
from gpu_rent.timing import clock_reset
|
||||
|
||||
clock_reset()
|
||||
log("запускаю проверку…")
|
||||
checks = run_doctor()
|
||||
_print_checks(checks)
|
||||
@@ -458,10 +468,13 @@ def up(
|
||||
)
|
||||
from gpu_rent.paths import vars_path
|
||||
from gpu_rent.prompts import MenuItem, prompt_menu
|
||||
from gpu_rent.timing import clock_elapsed, clock_reset, format_duration
|
||||
from gpu_rent.varsfile import upsert_vars
|
||||
|
||||
clock_reset()
|
||||
log("запускаю проверку…")
|
||||
checks = run_doctor()
|
||||
log(f"проверка заняла {format_duration(clock_elapsed())}")
|
||||
code = _print_checks(checks, quiet=not verbose)
|
||||
if code != 0:
|
||||
raise typer.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user