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

View file

@ -1,9 +1,13 @@
import logging
from geventconnpool import ConnectionPool
from epplibwrapper import RegistryError
from epplibwrapper.errors import LoginError
from epplibwrapper.errors import RegistryError, LoginError
from epplibwrapper.socket import Socket
try:
from epplib.commands import Hello
except ImportError:
pass
logger = logging.getLogger(__name__)
class EppConnectionPool(ConnectionPool):
@ -20,11 +24,17 @@ class EppConnectionPool(ConnectionPool):
return connection
except LoginError as err:
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
def _keepalive(self, connection):
pass
def _keepalive(self, c):
"""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:
"""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_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
# region: Security and Privacy----------------------------------------------###