diff --git a/Dockerfile b/Dockerfile index e8300a5a..79231bfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:8000/api/admin/health', timeout=5)" || exit 1 # Run the application -CMD exec uvicorn app:app --host 0.0.0.0 --port ${PORT:-8000} --workers 1 --timeout-graceful-shutdown 5 +CMD exec gunicorn app:app --bind 0.0.0.0:${PORT:-8000} --timeout 600 --worker-class uvicorn.workers.UvicornWorker --workers 1 diff --git a/app.py b/app.py index 74deb617..a69e9a7e 100644 --- a/app.py +++ b/app.py @@ -730,7 +730,19 @@ logger.info(f"Feature router load results: {featureLoadResults}") if __name__ == "__main__": - import uvicorn - port = int(os.environ.get("PORT", 8000)) - uvicorn.run("app:app", host="0.0.0.0", port=port, workers=1, timeout_graceful_shutdown=5) \ No newline at end of file + + try: + from gunicorn.app.wsgiapp import WSGIApplication # noqa: F401 + import subprocess + import sys + subprocess.run([ + sys.executable, "-m", "gunicorn", "app:app", + "--bind", f"0.0.0.0:{port}", + "--timeout", "600", + "--worker-class", "uvicorn.workers.UvicornWorker", + "--workers", "1", + ], check=True) + except ImportError: + import uvicorn + uvicorn.run("app:app", host="0.0.0.0", port=port, workers=1, timeout_graceful_shutdown=5) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3d8ee88a..9aafd048 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ fastapi==0.115.0 # Upgraded for Pydantic v2 compatibility websockets==12.0 uvicorn==0.23.2 +gunicorn==23.0.0 python-multipart==0.0.6 httpx>=0.25.2 pydantic>=2.0.0 # Upgraded to v2 for compatibility