Files
DashBoard/gunicorn.conf.py
egg c38b5f646a feat(modernization): promote deferred routes to in-scope and unify page header styles
Promote /tables, /excel-query, /query-tool, /mid-section-defect from
deferred to full shell-governed in-scope routes with canonical redirects,
content contracts, governance artifacts, and updated CI gates.

Unify all page header gradients to #667eea → #764ba2 and h1 font-size
to 24px for visual consistency across all dashboard pages. Remove
Native Route-View dev annotations from job-query, excel-query, and
query-tool headers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 13:20:06 +08:00

53 lines
2.0 KiB
Python

import os
bind = os.getenv("GUNICORN_BIND", "0.0.0.0:8080")
workers = int(os.getenv("GUNICORN_WORKERS", "2")) # 2 workers for redundancy
threads = int(os.getenv("GUNICORN_THREADS", "4"))
worker_class = "gthread"
# Timeout settings - critical for dashboard stability.
# Keep this above slow-query timeout paths (e.g. query-tool 120s) and DB pool timeout.
timeout = int(os.getenv("GUNICORN_TIMEOUT", "130"))
graceful_timeout = int(os.getenv("GUNICORN_GRACEFUL_TIMEOUT", "60"))
keepalive = 5 # Keep-alive connections timeout
# Worker lifecycle management - prevent state accumulation.
# Make these configurable so high-load test environments can raise the ceiling.
max_requests = int(os.getenv("GUNICORN_MAX_REQUESTS", "5000"))
max_requests_jitter = int(os.getenv("GUNICORN_MAX_REQUESTS_JITTER", "500"))
# ============================================================
# Worker Lifecycle Hooks
# ============================================================
def worker_exit(server, worker):
"""Clean up background threads and database connections when worker exits."""
# Stop background sync threads first
try:
from mes_dashboard.services.realtime_equipment_cache import (
stop_equipment_status_sync_worker
)
stop_equipment_status_sync_worker()
except Exception as e:
server.log.warning(f"Error stopping equipment sync worker: {e}")
try:
from mes_dashboard.core.cache_updater import stop_cache_updater
stop_cache_updater()
except Exception as e:
server.log.warning(f"Error stopping cache updater: {e}")
try:
from mes_dashboard.core.redis_client import close_redis
close_redis()
except Exception as e:
server.log.warning(f"Error closing redis client: {e}")
# Then dispose database connections
try:
from mes_dashboard.core.database import dispose_engine
dispose_engine()
except Exception as e:
server.log.warning(f"Error disposing database engine: {e}")