Skip to content

Switch local API dev server to use gunicorn --reload instead of Django's runserver #2814

Closed

Description

Problem

Stems from #2566

runserver does not support critical features we will need after converting the app to ASGI:

  1. Actually running the ASGI app in full asynchrony
  2. Multiple workers (to test production configuration)

We're also making the configuration slightly more complex by moving to ASGI, relying on gunicorn and uvicorn workers.

Description

To anticipate these complexities and make the local development environment (a) behave more like production and (b) require fewer changes when switching to full ASGI, swap out manage.py runserver for gunicorn --reload. Once we switch to ASGI in #2790, we'll either continue using gunicorn for development (with multiple workers) or can switch to uvicorn --reload.

runserver handles static file serving locally, while gunicorn and uvicorn won't know what to do. In production we rely on nginx to handle this. We could set up Nginx locally to front the API service, but to keep this simple, it's easier to conditionally add the static route handler that runserver uses to the API's urls configuration. See these changes as an example (which require supporting changes for the ENVIRONMENT variable and changes to the static file configuration generally, all present in that commit).

Additional context

Something along these lines will be necessary for ASGI conversion anyway. Doing this as a separate issue again reduces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions