[FEAT] (프로젝트 구성): 초기 프로젝트 구성
v0.1 (2025-11-13) - Flask, Gunicorn, gevent, MariaDB, Redis, Swagger, logging 기본 구성 완료;
This commit is contained in:
53
src/gunicorn_config.py
Normal file
53
src/gunicorn_config.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Gunicorn 설정 파일
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 프로젝트 루트 경로 추가
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
import settings
|
||||
|
||||
# Worker 설정
|
||||
workers = settings.GUNICORN_WORKERS
|
||||
worker_class = settings.GUNICORN_WORKER_CLASS
|
||||
worker_connections = settings.GUNICORN_WORKER_CONNECTIONS
|
||||
threads = settings.GUNICORN_THREADS
|
||||
|
||||
# 서버 바인딩
|
||||
bind = f'{settings.HOST}:{settings.PORT}'
|
||||
|
||||
# 타임아웃 설정
|
||||
timeout = settings.GUNICORN_TIMEOUT
|
||||
keepalive = settings.GUNICORN_KEEPALIVE
|
||||
graceful_timeout = settings.GUNICORN_GRACEFUL_TIMEOUT
|
||||
|
||||
# 재시작 설정 (메모리 누수 방지)
|
||||
max_requests = settings.GUNICORN_MAX_REQUESTS
|
||||
max_requests_jitter = settings.GUNICORN_MAX_REQUESTS_JITTER
|
||||
|
||||
# 로깅 설정
|
||||
accesslog = settings.GUNICORN_ACCESSLOG
|
||||
errorlog = settings.GUNICORN_ERRORLOG
|
||||
loglevel = settings.GUNICORN_LOGLEVEL
|
||||
|
||||
# 프로세스 네임
|
||||
proc_name = "nuriq_server"
|
||||
|
||||
# hook 함수
|
||||
def on_starting(server):
|
||||
"""
|
||||
Gunicorn 마스터 프로세스가 시작될 때 한번만 실행
|
||||
워커가 생성되기 전 실행, 전역 초기화 작업
|
||||
"""
|
||||
server.log.info("[Gunicorn] 마스터 프로세스 시작 중 ...")
|
||||
|
||||
# Flask 앱 컨텍스트 내에서 초기화 작업 수행
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
|
||||
def post_worker_init(worker):
|
||||
"""각 워커 프로세스 초기화된 후 사용"""
|
||||
worker.log.info(f"Worker {worker.pid} 초기화 완료")
|
||||
Reference in New Issue
Block a user