Django Database Connection Retrier
Automatically try to re-establish Django database connections when they fail due to DNS errors.
When the Django app (dbconnectionretrier) loads, a hook is installed in Django's BaseDatabaseWrapper.ensure_connection that catches django.db.OperationalError. If the error raised is a DNS error, the connction attempt is retried synchronously three times.
Tested on Django 2.0-2.3 and Python 3.7 and 3.8. Might work with other versions of Django and Python.
Installation
-
Install the package from PyPi:
$ pip install django-db-connection-retrier -
Add
dbconnectionretrierto yourINSTALLED_APPS:INSTALLED_APPS = [ 'dbconnectionretrier', ... ]
Manual usage
Adding dbconnectionretrier to INSTALLED_APPS enables automatic connection retrying. Want more granular control over patching?
Globally
from dbconnectionretrier.patch import patch_ensure_connection
# after this line executes, connection retrying is enabled
patch = patch_ensure_connection()
# after this line, the connection retrying is disabled
patch.rollback()
Context manager
from dbconnectionretrier.patch import patch_ensure_connection_contextual
with patch_ensure_connection_contextual():
# all code inside this block benefits from connection retrying
Release files for django-db-connection-retrier 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-db-connection-retrier-1.0.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_db_connection_retrier-1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / django-db-connection-retrier-1.0.tar.gz
| Download URL | django-db-connection-retrier-1.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03728c748644fdc28e015c8df3f9e7038aca96522325bb3be4fd89f6a3787146
|
|
BLAKE2b-256 checksum How to use checksums |
06c4f1dfc34a45ad8f03a9d5a5b80d6ca379efe2a5a6757218564aebecfcdf51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.2
|
Release files / django_db_connection_retrier-1.0-py3-none-any.whl
| Download URL | django_db_connection_retrier-1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b88c26a66a2a97ee8f5ea657a0437c76fd9bbf6654c7832aeda6421e6c862cfc
|
|
BLAKE2b-256 checksum How to use checksums |
0d356dd9edf163512611b30c2792f80cd5e1930aec4ca6ac2e213317dd1e7fe2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.2
|