From 9251b47cbff4cd1b2de181ffc0add315147f283c Mon Sep 17 00:00:00 2001 From: Kurbanov Bulat Date: Fri, 4 Feb 2022 12:53:44 +0300 Subject: [PATCH] Add healthcheck --- docker/production.dockerfile | 1 + scripts/healthcheck.py | 11 +++++++++++ src/app/views.py | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 scripts/healthcheck.py diff --git a/docker/production.dockerfile b/docker/production.dockerfile index 783a0d0..cc33208 100644 --- a/docker/production.dockerfile +++ b/docker/production.dockerfile @@ -32,6 +32,7 @@ COPY --from=build-image $VENV_PATH $VENV_PATH ENV PATH="$VENV_PATH/bin:$PATH" COPY ./scripts/start_production.sh /root/ +COPY ./scripts/healthcheck.py /root/ EXPOSE 8080 diff --git a/scripts/healthcheck.py b/scripts/healthcheck.py new file mode 100644 index 0000000..b7bd530 --- /dev/null +++ b/scripts/healthcheck.py @@ -0,0 +1,11 @@ +import os + +import httpx + + +response = httpx.get( + "http://localhost:8080/api/v1/healthcheck", + headers={"Authorization": os.environ["API_KEY"]}, +) +print(f"HEALTHCHECK STATUS: {response.status_code}") +exit(0 if response.status_code == 200 else 1) diff --git a/src/app/views.py b/src/app/views.py index 2736b4b..beae414 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -108,3 +108,8 @@ async def update_cache(request: Request): await arq_pool.enqueue_job("check_books") return "Ok!" + + +@router.get("/healthcheck") +async def healthcheck(): + return "Ok!"