Healthcheck
This commit is contained in:
parent
4930f3c991
commit
21e30b2e16
10
README.md
10
README.md
|
@ -1,3 +1,11 @@
|
|||
# hellocomputer
|
||||
|
||||
Analytics with natural language
|
||||
Analytics with natural language
|
||||
|
||||
```
|
||||
uv pip install -r requirements.in
|
||||
```
|
||||
|
||||
```
|
||||
uvicorn hellocomputer.main:app --host localhost
|
||||
```
|
|
@ -1,12 +1,41 @@
|
|||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, status
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import hellocomputer
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel
|
||||
|
||||
static_path = Path(hellocomputer.__file__).parent / "static"
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class HealthCheck(BaseModel):
|
||||
"""Response model to validate and return when performing a health check."""
|
||||
|
||||
status: str = "OK"
|
||||
|
||||
|
||||
@app.get(
|
||||
"/health",
|
||||
tags=["healthcheck"],
|
||||
summary="Perform a Health Check",
|
||||
response_description="Return HTTP Status Code 200 (OK)",
|
||||
status_code=status.HTTP_200_OK,
|
||||
response_model=HealthCheck,
|
||||
)
|
||||
def get_health() -> HealthCheck:
|
||||
"""
|
||||
## Perform a Health Check
|
||||
Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker
|
||||
to ensure a robust container orchestration and management is in place. Other
|
||||
services which rely on proper functioning of the API service will not deploy if this
|
||||
endpoint returns any other HTTP status code except 200 (OK).
|
||||
Returns:
|
||||
HealthCheck: Returns a JSON response with the health status
|
||||
"""
|
||||
return HealthCheck(status="OK")
|
||||
|
||||
|
||||
app.mount(
|
||||
"/",
|
||||
StaticFiles(directory=static_path, html=True, packages=["bootstrap4"]),
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
<title>Bootstrap demo</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
|
||||
<script src="https://unpkg.com/htmx.org@1.9.12"
|
||||
integrity="sha384-ujb1lZYygJmzgSwoxRggbCHcjc0rB2XoQrxeTUQyRjrOnlCoYta87iKBWq3EsdM2"
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello, world!</h1>
|
||||
<p>
|
||||
<div hx-get="/health" hx-swap="outerHTML">Swap!</div>
|
||||
</p>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
|
||||
crossorigin="anonymous"></script>
|
||||
|
|
Loading…
Reference in a new issue