feat: move from gunicorn to waitress

Waitress, unlike unicorn, is multi-threaded. As it does not do access logs
by default, the app needs to be wrapped in TransLogger before being passed to
Waitress.

To make the switch, a custom registry is now also used instead of the global REGISTRY
as the default registry for the app. As part of this change, the default
prometheus metrics are then also registered with this new registry.

Closes: #72
This commit is contained in:
Ana Custura 2024-12-04 12:57:09 +00:00 committed by irl
parent ffe097b24f
commit c50d341c26
4 changed files with 27 additions and 15 deletions

11
run_waitress.py Normal file
View file

@ -0,0 +1,11 @@
import os
from waitress import serve
from paste.translogger import TransLogger
from app.__init__ import app
from flask_migrate import upgrade
# equivalent of running flask db upgrade
with app.app_context():
upgrade()
serve(TransLogger(app), host=os.environ["WAITRESS_RUN_HOST"], port=os.environ["WAITRESS_RUN_PORT"], threads=int(os.environ["WAITRESS_THREADS"]))