Skip to content

Commit

Permalink
allows setting max retries on the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dwjorgeb authored Feb 27, 2023
1 parent 4110c1a commit 5f27417
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django_dbconn_retry/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import utils as django_db_utils
from django.db.backends.base import base as django_db_base
from django.dispatch import Signal
from django.conf import settings

from typing import Union, Tuple, Callable, List # noqa. flake8 #118

Expand Down Expand Up @@ -51,7 +52,7 @@ def ensure_connection_with_retries(self: django_db_base.BaseDatabaseWrapper) ->
self.connect()
except Exception as e:
if isinstance(e, _operror_types):
if hasattr(self, "_connection_retries") and self._connection_retries >= 1:
if hasattr(self, "_connection_retries") and self._connection_retries >= getattr(settings, "MAX_DBCONN_RETRIES", 1):
_log.error("Reconnecting to the database didn't help %s", str(e))
del self._in_connecting
post_reconnect.send(self.__class__, dbwrapper=self)
Expand Down

0 comments on commit 5f27417

Please sign in to comment.