Package: django-dbconn-retry-python27
Django Database Connection Autoreconnect========================================.. image:: https://coveralls.io/repos/github/jdelic/django-dbconn-retry/badge.svg?branch=HEAD:target: https://coveralls.io/github/jdelic/django-dbconn-retry?branch=HEAD.. image:: https://travis-ci.org/jdelic/django-dbconn-retry.svg?branch=master:target: https://travis-ci.org/jdelic/django-dbconn-retryThis library monkeypatches ``django.db.backends.base.BaseDatabaseWrapper`` sothat when a database operation fails because the underlying TCP connection wasalready closed, it first tried to reconnect, instead of immediately raisingan ``OperationException``.Why is this useful?-------------------I use `HAProxy`_ as a load-balancer in front of my PostgreSQL databases allthe time, sometimes in addition to ``pgbouncer``. Even though you can mostlyprevent surprises by enabling TCP keep-alive packets through `tcpka`_,`clitcpka`_ and `srvtcpka`_, I still encounter situations where theunderlying TCP connection has been closed through the load-balancer. Most oftenthis results in.. code-block::django.db.utils.OperationalError: server closed the connection unexpectedlyThis probably means the server terminated abnormally before or whileprocessing the request.This library patches Django such that it try to reconnect once before failing.Another application of this is when using `Hashicorp Vault`_, wherecredentials for a database connection can expire at any time and then need tobe refreshed from Vault.How to install?---------------Just pull the library in using ``pip install django-dbconn-retry``. Then add``django_dbconn_retry`` to ``INSTALLED_APPS`` in your ``settings.py``.Settings---------------DATABASES = {'default': {...'MAX_RETRIES': 2,  #'RETRY_DELAY': .500,  # in seconds}}Signals-------The library provides an interface for other code to plug into the process to,for example, allow `12factor-vault`_ to refresh the database credentialsbefore the code tries to reestablish the database connection. These areimplemented using `Django Signals`_.===========================  ==================================================Signal                       Description===========================  ==================================================``pre_reconnect``            Installs a hook of the type``Callable[[type, BaseDatabaseWrapper], None]``that will be called before the library tries toreestablish a connection. 12factor-vault uses thisto refresh the database credentials from Vault.``post_reconnect``           Installs a hook of the type``Callable[[type, BaseDatabaseWrapper], None]``that will be called after the library tried toreestablish the connection. Success or failure hasnot been tested at this point. So the connectionmay be in any state.===========================  ==================================================License=======Copyright (c) 2018, Jonas MaurusAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this softwarewithout specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE... _12factor-vault: https://github.com/jdelic/12factor-vault/.. _Django Signals: https://docs.djangoproject.com/en/dev/topics/signals/.. _HAProxy: http://www.haproxy.org/.. _tcpka:https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20tcpka.. _clitcpka:https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-option%20clitcpka.. _srvtcpka:https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20srvtcpka.. _Hashicorp Vault: https://vaultproject.io/