Add settings for pooling, keep_alive

This commit is contained in:
zandercymatics 2023-10-12 10:16:22 -06:00
parent a02d27aaec
commit 3a28a3a362
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 28 additions and 9 deletions

View file

@ -17,7 +17,6 @@ from django.conf import settings
from .cert import Cert, Key from .cert import Cert, Key
from .errors import LoginError, RegistryError from .errors import LoginError, RegistryError
from .socket import Socket
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -64,11 +63,11 @@ class EPPLibWrapper:
) )
options = { options = {
# Pool size # Pool size
"size": 10, "size": settings.EPP_CONNECTION_POOL_SIZE,
# Which errors the pool should look out for # Which errors the pool should look out for
"exc_classes": (LoginError, RegistryError,), "exc_classes": (LoginError, RegistryError,),
# Should we ping the connection on occasion to keep it alive? # Occasionally pings the registry to keep the connection alive
"keepalive": None, "keepalive": settings.POOL_KEEP_ALIVE,
} }
self._pool = EppConnectionPool(client=self._client, login=self._login, options=options) self._pool = EppConnectionPool(client=self._client, login=self._login, options=options)

View file

@ -1,9 +1,13 @@
import logging import logging
from geventconnpool import ConnectionPool from geventconnpool import ConnectionPool
from epplibwrapper import RegistryError from epplibwrapper.errors import RegistryError, LoginError
from epplibwrapper.errors import LoginError
from epplibwrapper.socket import Socket from epplibwrapper.socket import Socket
try:
from epplib.commands import Hello
except ImportError:
pass
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class EppConnectionPool(ConnectionPool): class EppConnectionPool(ConnectionPool):
@ -20,11 +24,17 @@ class EppConnectionPool(ConnectionPool):
return connection return connection
except LoginError as err: except LoginError as err:
message = "_new_connection failed to execute due to a registry login error." message = "_new_connection failed to execute due to a registry login error."
logger.warning(message, exc_info=True) logger.error(message, exc_info=True)
raise RegistryError(message) from err raise RegistryError(message) from err
def _keepalive(self, connection): def _keepalive(self, c):
pass """Sends a command to the server to keep the connection alive."""
try:
# Sends a ping to EPPLib
c.send(Hello())
except Exception as err:
logger.error("Failed to keep the connection alive.", exc_info=True)
raise RegistryError("Failed to keep the connection alive.") from err
def create_socket(self, client, login) -> Socket: def create_socket(self, client, login) -> Socket:
"""Creates and returns a socket instance""" """Creates and returns a socket instance"""

View file

@ -534,6 +534,16 @@ SECRET_REGISTRY_KEY = secret_registry_key
SECRET_REGISTRY_KEY_PASSPHRASE = secret_registry_key_passphrase SECRET_REGISTRY_KEY_PASSPHRASE = secret_registry_key_passphrase
SECRET_REGISTRY_HOSTNAME = secret_registry_hostname SECRET_REGISTRY_HOSTNAME = secret_registry_hostname
# endregion
# region: Registry Connection Pool----------------------------------------------------------###
# Use this variable to set the size of our connection pool in client.py
# WARNING: Setting this value too high could cause frequent app crashes!
EPP_CONNECTION_POOL_SIZE = 10
# Determines if we should ping open connections
POOL_KEEP_ALIVE = True
# endregion # endregion
# region: Security and Privacy----------------------------------------------### # region: Security and Privacy----------------------------------------------###