Files
Scrobbler/gunicorn.conf.py
mattandClaude Sonnet 5.5 ad383b602e
CI / notify (push) Successful in 6s
CI / lint (push) Successful in 18s
CI / test (push) Successful in 5m26s
CI / validate-monitoring (push) Successful in 15s
CI / federation-interop (push) Successful in 1m17s
CI / images (push) Successful in 33s
CI / assets (push) Successful in 9s
CI / python-package (push) Successful in 18s
CI / trigger-deploy (push) Successful in 3s
Configurable logging for the API and worker (SCR-5)
Shared LOG_LEVEL/LOG_FORMAT (text or json) set up in create_app, per-task
activity and duration logs in the worker, and more context on delivery,
inbox and import failures. Alembic's fileConfig no longer disables loggers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 23:30:54 +01:00

47 lines
1.5 KiB
Python

"""Gunicorn settings for the API. Metrics from every worker are aggregated through
prometheus_client's multiprocess mode and served by the master on METRICS_PORT."""
import os
import shutil
# Must be set before prometheus_client is imported by anything.
MULTIPROC_DIR = os.environ.setdefault("PROMETHEUS_MULTIPROC_DIR", "/tmp/scrobbler-metrics")
wsgi_app = "scrobbler:create_app()"
bind = os.environ.get("BIND", "0.0.0.0:8000")
workers = int(os.environ.get("WEB_CONCURRENCY", "2"))
accesslog = "-"
loglevel = os.environ.get("LOG_LEVEL", "INFO").lower()
forwarded_allow_ips = os.environ.get("FORWARDED_ALLOW_IPS", "127.0.0.1")
# gunicorn 26's control socket lives in $HOME, which the container user doesn't have.
control_socket_disable = True
def post_fork(server, worker):
# Gunicorn's own messages go through the app's handler too, so the format is uniform.
import logging
gunicorn_error = logging.getLogger("gunicorn.error")
gunicorn_error.handlers.clear()
gunicorn_error.propagate = True
def on_starting(server):
# Stale files from a previous run would double-count.
shutil.rmtree(MULTIPROC_DIR, ignore_errors=True)
os.makedirs(MULTIPROC_DIR, exist_ok=True)
def when_ready(server):
from scrobbler.metrics.server import start_metrics_server
start_metrics_server(
int(os.environ.get("METRICS_PORT", "9100")), os.environ.get("DATABASE_URL")
)
def child_exit(server, worker):
from prometheus_client import multiprocess
multiprocess.mark_process_dead(worker.pid)