- 新增 Redis 表級快取機制,減少 Oracle 查詢負載 - 實作 CacheUpdater 背景任務,每 10 分鐘檢查 SYS_DATE 並更新快取 - 所有 WIP API 端點改為 cache-first + Oracle fallback 架構 - 新增 /health 端點顯示資料庫、Redis、快取狀態 - 前端 Portal 新增即時健康狀態指示器 - SQLAlchemy 連線設置 call_timeout=55s 防止 Worker 卡死 - Gunicorn 加入 max_requests=1000 確保 Worker 定期重啟 - 完整測試覆蓋:67 項單元/整合/E2E 測試 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
29 lines
1.1 KiB
Python
29 lines
1.1 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
|
|
timeout = 65 # Worker timeout: must be > call_timeout (55s)
|
|
graceful_timeout = 10 # Graceful shutdown timeout (reduced for faster restart)
|
|
keepalive = 5 # Keep-alive connections timeout
|
|
|
|
# Worker lifecycle management - prevent state accumulation
|
|
max_requests = 1000 # Restart worker after N requests
|
|
max_requests_jitter = 100 # Random jitter to prevent simultaneous restarts
|
|
|
|
|
|
# ============================================================
|
|
# Worker Lifecycle Hooks
|
|
# ============================================================
|
|
|
|
def worker_exit(server, worker):
|
|
"""Clean up database connections when worker exits."""
|
|
try:
|
|
from mes_dashboard.core.database import dispose_engine
|
|
dispose_engine()
|
|
except Exception as e:
|
|
server.log.warning(f"Error disposing database engine: {e}")
|