Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use daphne (ASGI) as the server #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release: ./manage.py migrate
web: gunicorn --bind 0.0.0.0:$PORT {{ cookiecutter.pkg_name }}.wsgi
web: daphne -b 0.0.0.0 -p $PORT {{ cookiecutter.pkg_name }}.asgi:application
worker: REMAP_SIGTERM=SIGQUIT celery --app {{ cookiecutter.pkg_name }}.celery worker --loglevel INFO --without-heartbeat
3 changes: 2 additions & 1 deletion {{ cookiecutter.project_slug }}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
include_package_data=True,
install_requires=[
'celery',
'daphne',
'django',
'django-allauth',
'django-configurations[database,email]',
Expand All @@ -48,7 +49,7 @@
# Production-only
'django-composed-configuration[prod]>=0.20',
'django-s3-file-field[s3]',
'gunicorn',
'psycopg[pool]',
],
extras_require={
'dev': [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from pathlib import Path

from composed_configuration import (
Expand All @@ -10,19 +11,23 @@
ProductionBaseConfiguration,
TestingBaseConfiguration,
)
import dj_database_url


class {{ cookiecutter.pkg_name.split('_')|map('capitalize')|join('') }}Mixin(ConfigMixin):
ASGI_APPLICATION = '{{ cookiecutter.pkg_name }}.asgi.application'
WSGI_APPLICATION = '{{ cookiecutter.pkg_name }}.wsgi.application'
ROOT_URLCONF = '{{ cookiecutter.pkg_name }}.urls'

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

@staticmethod
def mutate_configuration(configuration: ComposedConfiguration) -> None:
# Install local apps first, to ensure any overridden resources are found first
configuration.INSTALLED_APPS = [
# Install local apps first, to ensure any overridden resources are found first
'{{ cookiecutter.pkg_name }}.{{ cookiecutter.first_app_name }}.apps.{{ cookiecutter.first_app_name.split('_')|map('capitalize')|join('') }}Config',
# Daphne must be listed before django.contrib.staticfiles in INSTALLED_APPS
'daphne',
] + configuration.INSTALLED_APPS

# Install additional apps
Expand All @@ -46,4 +51,17 @@ class ProductionConfiguration({{ cookiecutter.pkg_name.split('_')|map('capitaliz


class HerokuProductionConfiguration({{ cookiecutter.pkg_name.split('_')|map('capitalize')|join('') }}Mixin, HerokuProductionBaseConfiguration):
pass
@property
def DATABASES(self): # noqa: N802
return {
'default': {
**dj_database_url.parse(os.environ['DATABASE_URL']),
'OPTIONS': {
'pool': {
# Adjust this pool size according to your postgres add-on service tier,
# web dyno count, number of workers, etc.
'max_size': 12,
},
},
},
}