-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgunicorn.conf.py
More file actions
25 lines (19 loc) · 806 Bytes
/
gunicorn.conf.py
File metadata and controls
25 lines (19 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
Gunicorn configuration for production deployment.
Uses UvicornWorker to run the FastAPI ASGI app. The on_starting hook runs
Alembic migrations once in the master process before any workers are forked,
ensuring a single, race-free initialization step.
"""
import multiprocessing
import os
from pathlib import Path
from typing import Any
from alembic import command
from alembic.config import Config
bind: str = "0.0.0.0:9000"
workers: int = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2 + 1))
worker_class: str = "uvicorn.workers.UvicornWorker"
def on_starting(_server: Any) -> None:
"""Apply Alembic migrations once before workers are spawned."""
alembic_config = Config(str(Path(__file__).resolve().parent / "alembic.ini"))
command.upgrade(alembic_config, "head")