Refactor healthcheck

This commit is contained in:
2022-02-12 13:38:36 +03:00
parent d93c16ffe8
commit 6b004002f1
3 changed files with 9 additions and 6 deletions

View File

@@ -1,11 +1,8 @@
import os
import httpx import httpx
response = httpx.get( response = httpx.get(
"http://localhost:8080/healthcheck", "http://localhost:8080/healthcheck"
headers={"Authorization": os.environ["API_KEY"]},
) )
print(f"HEALTHCHECK STATUS: {response.status_code}") print(f"HEALTHCHECK STATUS: {response.status_code}")
exit(0 if response.status_code == 200 else 1) exit(0 if response.status_code == 200 else 1)

View File

@@ -35,6 +35,11 @@ async def get_filename(book_id: int, file_type: str):
return _get_filename(book.remote_id, book, file_type) return _get_filename(book.remote_id, book, file_type)
@router.get("/healthcheck") healthcheck_router = APIRouter(
tags=["healthcheck"]
)
@healthcheck_router.get("/healthcheck")
async def healthcheck(): async def healthcheck():
return "Ok!" return "Ok!"

View File

@@ -2,13 +2,14 @@ from fastapi import FastAPI
from prometheus_fastapi_instrumentator import Instrumentator from prometheus_fastapi_instrumentator import Instrumentator
from app.views import router from app.views import router, healthcheck_router
def start_app() -> FastAPI: def start_app() -> FastAPI:
app = FastAPI() app = FastAPI()
app.include_router(router) app.include_router(router)
app.include_router(healthcheck_router)
Instrumentator().instrument(app).expose(app, include_in_schema=True) Instrumentator().instrument(app).expose(app, include_in_schema=True)