Skip to content

Commit

Permalink
Migrate from WSGI to ASGI
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys0dev committed Jun 1, 2023
1 parent 9100afd commit e0aa202
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 5 deletions.
7 changes: 7 additions & 0 deletions cl/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cl.settings")

application = get_asgi_application()
3 changes: 3 additions & 0 deletions cl/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
ROOT_URLCONF = "cl.urls"

INSTALLED_APPS = [
"daphne",
"django.contrib.admin",
"django.contrib.admindocs",
"django.contrib.contenttypes",
Expand Down Expand Up @@ -189,6 +190,8 @@
INSTALLED_APPS.append("django_extensions")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")

ASGI_APPLICATION = "cl.asgi.application"


################
# Misc. Django #
Expand Down
7 changes: 3 additions & 4 deletions docker/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ CMD python /opt/courtlistener/manage.py migrate && \
#freelawproject/courtlistener:latest-web-prod
FROM python-base as web-prod

CMD gunicorn cl_wsgi:application \
--chdir /opt/courtlistener/docker/django/wsgi-configs/ \
CMD gunicorn cl_asgi:application \
--chdir /opt/courtlistener/docker/django/asgi-configs/ \
--user www-data \
--group www-data \
# Set high number of workers. Docs recommend 2-4× core count`
--workers ${NUM_WORKERS:-48} \
--worker-class gthread \
--threads 2 \
--worker-class uvicorn.workers.UvicornWorker \
# Allow longer queries to solr.
--limit-request-line 6000 \
# Reset each worker once in a while
Expand Down
9 changes: 9 additions & 0 deletions docker/django/asgi-configs/cl_asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os
import sys

from django.core.asgi import get_asgi_application

os.environ["DJANGO_SETTINGS_MODULE"] = "cl.settings"

sys.path.append("/opt/courtlistener")
application = get_asgi_application()
Loading

0 comments on commit e0aa202

Please sign in to comment.