Skip to content

Commit

Permalink
Add a health check endpoint
Browse files Browse the repository at this point in the history
Update shell context for GH workflow
Add more todo(s)
  • Loading branch information
dormant-user committed Aug 26, 2024
1 parent e9c6830 commit 29bad4d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
echo "::notice title=DryRun::Setting dry run to false for '${{ github.event_name }}' event"
echo "dry_run=false" >> $GITHUB_ENV
fi
shell: bash
- uses: thevickypedia/pypi-publisher@v3
env:
token: ${{ secrets.PYPI_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions pyninja/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi.exceptions import HTTPException


# todo: move this out of "exceptions"
class APIResponse(HTTPException):
"""Custom ``HTTPException`` from ``FastAPI`` to wrap an API response.
Expand Down
1 change: 1 addition & 0 deletions pyninja/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def get_service_manager() -> ServiceManager:
except KeyError:
# This shouldn't happen programmatically, but just in case
# https://docs.pydantic.dev/latest/errors/validation_errors/#model_type
# todo: Create an overrided object under exceptions.py
raise ValidationError.from_exception_data(
title="PyNinja",
line_errors=[
Expand Down
11 changes: 11 additions & 0 deletions pyninja/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ async def docs() -> RedirectResponse:
return RedirectResponse("/docs")


async def health() -> exceptions.APIResponse:
"""Health check for PyNinja.
Returns:
APIResponse:
Returns a health check response with status code 200.
"""
raise exceptions.APIResponse(status_code=HTTPStatus.OK, detail=HTTPStatus.OK.phrase)


def get_all_routes() -> List[APIRoute]:
"""Get all the routes to be added for the API server.
Expand All @@ -247,6 +257,7 @@ def get_all_routes() -> List[APIRoute]:
]
routes = [
APIRoute(path="/", endpoint=docs, methods=["GET"], include_in_schema=False),
APIRoute(path="/health", endpoint=health, methods=["GET"], include_in_schema=False),
APIRoute(
path="/service-status",
endpoint=service_status,
Expand Down

0 comments on commit 29bad4d

Please sign in to comment.