First pass EPP retry

This commit is contained in:
Erin 2023-12-05 11:35:08 -08:00
parent c569db24f3
commit 4a25642d8d
No known key found for this signature in database
GPG key ID: 1CAD275313C62460
4 changed files with 22 additions and 4 deletions

View file

@ -17,7 +17,7 @@ except ImportError:
from django.conf import settings
from .cert import Cert, Key
from .errors import LoginError, RegistryError
from .errors import ErrorCode, LoginError, RegistryError
from .socket import Socket
from .utility.pool import EPPConnectionPool
@ -115,7 +115,7 @@ class EPPLibWrapper:
except TransportError as err:
message = f"{cmd_type} failed to execute due to a connection error."
logger.error(f"{message} Error: {err}", exc_info=True)
raise RegistryError(message) from err
raise RegistryError(message, code=ErrorCode.TRANSPORT_ERROR) from err
except LoginError as err:
# For linter due to it not liking this line length
text = "failed to execute due to a registry login error."
@ -159,11 +159,15 @@ class EPPLibWrapper:
self.start_connection_pool()
counter = 0 # we'll try 3 times
logger.info("Counter set to: ", counter)
while True:
try:
logger.info("Trying self._send(command)")
return self._send(command)
except RegistryError as err:
if err.should_retry() and counter < 3:
logger.info("Exception found")
if counter < 3 and (err.should_retry() or err.is_transport_error()):
logger.info("Retrying transport error. Attempt #", counter)
counter += 1
sleep((counter * 50) / 1000) # sleep 50 ms to 150 ms
else: # don't try again