From 90e5c04369ec3f878346e72ee380453976b390f6 Mon Sep 17 00:00:00 2001 From: Becky Smith Date: Mon, 8 Jan 2024 14:53:14 +0000 Subject: [PATCH] Run webserver with gunicorn --- Procfile | 2 +- docker/docker-compose.yaml | 2 +- ebmbot/webserver/__main__.py | 7 ++++--- gunicorn/conf.py | 17 +++++++++++++++++ pyproject.toml | 3 +++ 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gunicorn/conf.py diff --git a/Procfile b/Procfile index e77f575c..de10ed71 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,4 @@ bot: python -m ebmbot.bot dispatcher: python -m ebmbot.dispatcher -web: python -m ebmbot.webserver +web: gunicorn --config /app/gunicorn/conf.py ebmbot.webserver:app release: rm -f /storage/.bot_startup_check diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 766a016c..19fb5d79 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -62,7 +62,7 @@ services: extends: service: dev container_name: bennettbot-webserver - command: python -m ebmbot.webserver + command: gunicorn --config /app/gunicorn/conf.py ebmbot.webserver:app # host:container ports: container port should match the port in WEBHOOK_ORIGIN ports: - "1234:1234" diff --git a/ebmbot/webserver/__main__.py b/ebmbot/webserver/__main__.py index 98e0715f..79e96c44 100644 --- a/ebmbot/webserver/__main__.py +++ b/ebmbot/webserver/__main__.py @@ -5,6 +5,7 @@ from . import app -logger.info("running ebmbot.webserver") -port = urlparse(settings.WEBHOOK_ORIGIN).port -app.run(host="0.0.0.0", port=port, load_dotenv=False, debug=False) +if __name__ == "__main__": + logger.info("running ebmbot.webserver") + port = urlparse(settings.WEBHOOK_ORIGIN).port + app.run(host="0.0.0.0", port=port, load_dotenv=False, debug=False) diff --git a/gunicorn/conf.py b/gunicorn/conf.py new file mode 100644 index 00000000..67fcd778 --- /dev/null +++ b/gunicorn/conf.py @@ -0,0 +1,17 @@ +from urllib.parse import urlparse + +from ebmbot import settings +from ebmbot.logger import logger + + +logger.info("running ebmbot.webserver") +port = urlparse(settings.WEBHOOK_ORIGIN).port + +bind = f"0.0.0.0:{port}" + +workers = 8 +timeout = 120 + +# Where to log to (stdout and stderr) +accesslog = "-" +errorlog = "-" diff --git a/pyproject.toml b/pyproject.toml index d81c6e9a..e796b98a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,9 @@ extend-ignore = [ [tool.ruff.isort] lines-after-imports = 2 +[tool.ruff.per-file-ignores] +"gunicorn/conf.py" = ["INP001"] + [tool.pytest.ini_options] env = [ "DB_PATH=tests/ebmbot.db",