This commit is contained in:
Waylon Walker 2023-06-06 09:57:21 -05:00
parent 6b1c60a550
commit 839cbd0dc0
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
17 changed files with 213 additions and 35 deletions

View file

@ -1,3 +1,4 @@
from rich.console import Console
import typer
import uvicorn
@ -27,3 +28,38 @@ def run(
),
):
uvicorn.run(**get_config().api_server.dict())
@api_app.command()
def status(
verbose: bool = typer.Option(
False,
callback=verbose_callback,
help="show the log messages",
),
):
import httpx
config = get_config()
host = config.api_server.host
port = config.api_server.port
url = f"http://{host}:{port}/docs"
try:
r = httpx.get(url)
if r.status_code == 200:
Console().print(f"[green]API: ([gold1]{url}[green]) is running")
else:
Console().print(f"[red]API: ([gold1]{url}[red]) is not running")
except httpx.ConnectError:
Console().print(f"[red]API: ([gold1]{url}[red]) is not running")
try:
with config.database.engine.connect():
Console().print(
f"[green]database: ([gold1]{config.database.engine}[green]) is running"
)
except Exception as e:
Console().print(
f"[red]database: ([gold1]{config.database.engine}[red]) is not running"
)