Align Gunicorn configuration with Uvicorn

- centralize config in gunicorn_config.py
- fix log level handling in Gunicorn
This commit is contained in:
yangdx
2025-02-28 20:41:11 +08:00
parent ff549a3a9c
commit c37b1e8aa7
4 changed files with 47 additions and 110 deletions

View File

@@ -86,7 +86,7 @@ class LightragPathFilter(logging.Filter):
def create_app(args):
# Setup logging
logger.setLevel(getattr(logging, args.log_level))
logger.setLevel(args.log_level)
set_verbose_debug(args.verbose)
# Verify that bindings are correctly setup
@@ -412,17 +412,10 @@ def create_app(args):
return app
def get_application():
def get_application(args=None):
"""Factory function for creating the FastAPI application"""
# Get args from environment variable
args_json = os.environ.get("LIGHTRAG_ARGS")
if not args_json:
args = parse_args() # Fallback to parsing args if env var not set
else:
import types
args = types.SimpleNamespace(**json.loads(args_json))
if args is None:
args = parse_args()
return create_app(args)
@@ -513,10 +506,7 @@ def main():
# Configure logging before parsing args
configure_logging()
args = parse_args()
# Save args to environment variable for child processes
os.environ["LIGHTRAG_ARGS"] = json.dumps(vars(args))
args = parse_args(is_uvicorn_mode=True)
display_splash_screen(args)
# Create application instance directly instead of using factory function

View File

@@ -111,10 +111,13 @@ def get_env_value(env_key: str, default: any, value_type: type = str) -> any:
return default
def parse_args() -> argparse.Namespace:
def parse_args(is_uvicorn_mode: bool = False) -> argparse.Namespace:
"""
Parse command line arguments with environment variable fallback
Args:
is_uvicorn_mode: Whether running under uvicorn mode
Returns:
argparse.Namespace: Parsed arguments
"""
@@ -287,9 +290,6 @@ def parse_args() -> argparse.Namespace:
args = parser.parse_args()
# Check if running under uvicorn mode (not Gunicorn)
is_uvicorn_mode = "GUNICORN_CMD_ARGS" not in os.environ
# If in uvicorn mode and workers > 1, force it to 1 and log warning
if is_uvicorn_mode and args.workers > 1:
original_workers = args.workers