diff --git a/Dockerfile b/Dockerfile index 1839824..853dbb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,5 +63,6 @@ CMD celery -A src.celery worker -c ${CONCURENCY:-4} -n "${celery}@%h" --max-task # FROM base as web COPY --from=uwsgi-compile /uwsgi /usr/local/bin/ +HEALTHCHECK CMD wget -q -O /dev/null http://localhost:8000/healthcheck/ || exit 1 CMD uwsgi --master --http :8000 --module src.web:app diff --git a/Makefile b/Makefile index a8c20cb..ff2b39d 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,6 @@ dev: worker: poetry run watchmedo auto-restart --directory src --patterns '*.py' --recursive -- celery -- -A src.celery worker --purge + +web: + poetry run flask --app src.web run --debug --port 8090 diff --git a/src/web.py b/src/web.py index b81eec0..7842c33 100644 --- a/src/web.py +++ b/src/web.py @@ -1,3 +1,6 @@ +import os + +import kombu from dotenv import load_dotenv from flask import Flask, render_template @@ -22,3 +25,10 @@ def confirm(key: str) -> str: user.save() return render_template("html/confirmation_ok.html") + + +@app.route("/healthcheck/") +def healthcheck() -> str: + with kombu.Connection(os.getenv("CELERY_BROKER_URL")) as connection: + connection.connect() + return "ok"