-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(async): add uvicorn, asgi, upgrade django=4.1 (#473)
> Why was this change necessary? Current version of django(3.2) doesn't support async tasks. > How does it address the problem? After upgrading to django>4.1 and running asgi server, the application can run tasks asynchronously. > Are there any side effects? Uvicorn config `--limit-concurrency` is not yet supported when running with Gunicorn. Need to test provisioner scripts before merging
- Loading branch information
Suneet Choudhary
authored
Nov 27, 2023
1 parent
2afafb2
commit d305b93
Showing
22 changed files
with
186 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ default_context: | |
enable_whitenoise: "y" | ||
add_celery: "y" | ||
add_graphql: "y" | ||
add_asgi: "y" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Standard Library | ||
import os | ||
|
||
# Third Party Stuff | ||
from django.core.asgi import get_asgi_application | ||
from dotenv import load_dotenv | ||
|
||
# Read .env file and set key/value inside it as environment variables | ||
# see: http://github.com/theskumar/python-dotenv | ||
load_dotenv(os.path.join(os.path.dirname(__file__), ".env")) | ||
|
||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.production") | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
{{cookiecutter.github_repository}}/provisioner/roles/project_data/tasks/asgi-setup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% raw %}--- | ||
- name: apt_get install asgi packages | ||
apt: pkg={{ item }} state=present | ||
with_items: | ||
- uuid-dev | ||
- libcap-dev | ||
- libpcre3-dev | ||
tags: ["configure"] | ||
|
||
- name: make sure project directory is owned by asgi group | ||
file: path={{ project_path }} state=directory owner={{user}} group={{asgi_group}} recurse=yes | ||
tags: ["configure"] | ||
|
||
- name: copy django-asgi logrotate | ||
template: src=django.logrotate.j2 | ||
dest=/etc/logrotate.d/asgi-{{ deploy_environment}}-{{project_name}}-django | ||
mode=644 | ||
tags: ["configure"] | ||
|
||
- name: make sure log directory exists | ||
file: path={{ project_log_dir }} state=directory owner={{asgi_user}} group={{asgi_group}} mode=751 recurse=yes | ||
tags: ["configure"] | ||
|
||
- name: copy Django asgi service to systemd | ||
template: src=django.asgi.ini.j2 | ||
dest=/etc/systemd/system/asgi-{{project_namespace}}.service | ||
mode=644 | ||
tags: ["deploy"] | ||
{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...kiecutter.github_repository}}/provisioner/roles/project_data/templates/django.asgi.ini.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% raw %}[Unit] | ||
Description={{ project_namespace }} gunicorn daemon | ||
After=network.target | ||
|
||
[Service] | ||
Environment=LC_ALL=en_US.utf-8 | ||
Environment=LANG=en_US.utf-8 | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier=gunicorn | ||
User={{ asgi_user }} | ||
Group={{ asgi_group }} | ||
WorkingDirectory={{ project_path }} | ||
ExecStart={{ venv_path }}/bin/gunicorn -w {{ asgi_workers }} --bind unix://{{ asgi_socket }} --access-logfile {{project_log_dir}}/asgi.log --capture-output --error-logfile {{project_log_dir}}/asgi-errors.log -k uvicorn.workers.UvicornWorker asgi:application | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
{{cookiecutter.github_repository}}/{{cookiecutter.main_module}}/graphql/middleware.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.