Set CONN_MAX_AGE to 60 seconds -- fixes #710 (#1382)

* Set CONN_MAX_AGE to 60 seconds -- fixes #710

Setting the value in the production config.

* Get CONN_MAX_AGE from the environment, default to 60 in .env

* Add test for CONN_MAX_AGE setting

* Remove duplication in default value & test cleanup

* Remove test for CONN_MAX_AGE value in settings
This commit is contained in:
Bruno Alla 2017-11-13 20:08:47 +00:00 committed by Shupeyko Nikita
parent b00b402774
commit 4f8cd89bb7
2 changed files with 4 additions and 1 deletions

View File

@ -169,7 +169,7 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [
('django.template.loaders.cached.Loader', [ ('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]), 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]),
] ]
{% set _DEFAULT_CONN_MAX_AGE=60 %}
# DATABASE CONFIGURATION # DATABASE CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
{% if cookiecutter.use_elasticbeanstalk_experimental.lower() == 'y' -%} {% if cookiecutter.use_elasticbeanstalk_experimental.lower() == 'y' -%}
@ -182,12 +182,14 @@ DATABASES = {
'PASSWORD': env('RDS_PASSWORD'), 'PASSWORD': env('RDS_PASSWORD'),
'HOST': env('RDS_HOSTNAME'), 'HOST': env('RDS_HOSTNAME'),
'PORT': env('RDS_PORT'), 'PORT': env('RDS_PORT'),
'CONN_MAX_AGE': env.int('CONN_MAX_AGE', default={{ _DEFAULT_CONN_MAX_AGE }}),
} }
} }
{% else %} {% else %}
# Use the Heroku-style specification # Use the Heroku-style specification
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ # Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
DATABASES['default'] = env.db('DATABASE_URL') DATABASES['default'] = env.db('DATABASE_URL')
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default={{ _DEFAULT_CONN_MAX_AGE }})
{%- endif %} {%- endif %}
# CACHING # CACHING

View File

@ -2,6 +2,7 @@
# PostgreSQL # PostgreSQL
POSTGRES_PASSWORD=mysecretpass POSTGRES_PASSWORD=mysecretpass
POSTGRES_USER=postgresuser POSTGRES_USER=postgresuser
CONN_MAX_AGE=
# Domain name, used by caddy # Domain name, used by caddy
DOMAIN_NAME={{ cookiecutter.domain_name }} DOMAIN_NAME={{ cookiecutter.domain_name }}