majuna/run_waitress.py
Ana Custura c50d341c26 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
2024-12-04 16:14:01 +00:00

11 lines
368 B
Python

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"]))