build: switch services to gunicorn with per-service config

Replace uvicorn with gunicorn + UvicornWorker in backend, runtime,
and schedule Dockerfiles. New gunicorn.conf.py per service exposes
bind/workers/timeout/graceful_timeout as GUNICORN_* env knobs.

Notable details:
- schedule: timeout=0 (disables gunicorn worker heartbeat) so long
  notebook execution isn't killed by gunicorn's silent-worker kill.
- All three configs: drop dead threads=4 setting; UvicornWorker is
  async and ignores threads.
- Pin gunicorn>=26.0.0 in each pyproject; uv.lock regenerated.
- Drop stale 'COPY contracts ./contracts' from runtime and schedule
  Dockerfiles (contracts dir was deleted in an earlier refactor;
  builds would have failed).
- backend Dockerfile: switch to uv sync layout matching runtime/
  schedule; add build deps for native wheels.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-31 15:07:45 +08:00
co-authored by Claude
parent 245f4d346d
commit b0f93d976f
10 changed files with 105 additions and 6 deletions
+1 -2
View File
@@ -20,9 +20,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
COPY pyproject.toml uv.lock ./
COPY common ./common
COPY contracts ./contracts
COPY runtime ./runtime
RUN UV_DEFAULT_INDEX="https://pypi.tuna.tsinghua.edu.cn/simple/" uv sync --frozen --no-dev --no-editable --package runtime
EXPOSE 8000
CMD ["uv", "run", "--frozen", "--package", "runtime", "uvicorn", "runtime.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uv", "run", "--frozen", "--package", "runtime", "gunicorn", "--config", "runtime/gunicorn.conf.py", "runtime.main:app"]
+15
View File
@@ -0,0 +1,15 @@
"""Gunicorn configuration for the runtime service.
Workers MUST stay at 1: file leases and Jupyter tickets live in
in-memory process state, so a second worker would split that state.
"""
import os
bind = os.getenv("GUNICORN_BIND", "0.0.0.0:8000")
workers = int(os.getenv("GUNICORN_WORKERS", "1"))
worker_class = "uvicorn.workers.UvicornWorker"
timeout = int(os.getenv("GUNICORN_TIMEOUT", "120"))
graceful_timeout = int(os.getenv("GUNICORN_GRACEFUL_TIMEOUT", "30"))
accesslog = "-"
errorlog = "-"
+5
View File
@@ -9,11 +9,16 @@ dependencies = [
"httpx==0.28.1",
"loguru==0.7.2",
"notebook",
"gunicorn>=26.0.0",
]
[tool.uv.sources]
common = { workspace = true }
[[tool.uv.index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
default = true
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"