diff --git a/gunicorn.conf.py b/gunicorn.conf.py index ef99279..0d44b3f 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -7,7 +7,6 @@ restart workers but keep the preloaded app object from the old master process. import os import sys -import fcntl import threading from sqlalchemy.engine import Engine @@ -94,23 +93,15 @@ def post_fork(server, worker): def post_worker_init(worker): - """Warm the expensive dashboard cache once per container start.""" + """Load the shared dashboard cache in every worker before user traffic.""" enabled = os.getenv("DASHBOARD_PREWARM_ON_WORKER_INIT", "1").lower() if enabled in {"0", "false", "no"}: return def _warm_dashboard_cache(): - lock_path = os.getenv("DASHBOARD_PREWARM_LOCK_PATH", "/tmp/momo-dashboard-prewarm.lock") try: - with open(lock_path, "w", encoding="utf-8") as lock_file: - try: - fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError: - worker.log.info("Dashboard cache prewarm already running; worker %s skips", worker.pid) - return - - from routes.dashboard_routes import warm_full_dashboard_cache - warm_full_dashboard_cache(reason=f"gunicorn-worker-{worker.pid}") + from routes.dashboard_routes import warm_full_dashboard_cache + warm_full_dashboard_cache(reason=f"gunicorn-worker-{worker.pid}") except Exception as exc: worker.log.warning("Dashboard cache prewarm failed in worker %s: %s", worker.pid, exc)