Giter VIP home page Giter VIP logo

django-postgresql-reconnect's Introduction

Django PostgreSQL backend with reconnection support

pyversions PyPi Status Docs Coverage PyPI status Quality Gate Status PyPI Downloads

Introduction

In some cases (network connection lost, load balancer issues) the connection to the database is lost without giving Django a notification. Django tries to use such a connection and gets errors because of it. For a correct recovery, we need to restart the application workers.

Install

$ pip install django-postgresql-reconnect

Integration

Handling connection issues when processing HTTP requests

# settings.py

DATABASES = {
    # The database back end that performs reconnect when the connection is closed
    'default': {
        'ENGINE': 'django_postgresql_reconnect.backend',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'pwd',
        'HOST': 'db_host',
        'RECONNECT': True,
    },
}

MIDDLEWARE = [
    # Middleware checks and reconnects before processing requests
    'django_postgresql_reconnect.middleware',
    ...
]

Decorator for using in other places.

For example, in management commands.

import django_postgresql_reconnect

@django_postgresql_reconnect.decorator
def some_awesome_function():
    ...

Testing

  1. Python 3.8+
  2. Install dependencies pip install poetry && poetry install

Check code style: poetry run flake8 Run tests: poetry run pytest

Tests reports are generated in tests/reports.

  • out.xml - JUnit test results
  • coverage.xml - Coverage xml results

To generate HTML coverage reports use: --cov-report html:tests/reports/cov_html

License

Django PostgreSQL Reconnect is released under the Apache License Version 2.0.

django-postgresql-reconnect's People

Contributors

zzzevaka avatar d3rky avatar ffaraone avatar maxipavlovic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.