diff --git a/.dev.env b/.dev.env index b3912fb5..1b049f25 100644 --- a/.dev.env +++ b/.dev.env @@ -73,6 +73,12 @@ GUNICORN_WEB_RELOAD=false # The Client Gateway /flush token. #CGW_FLUSH_TOKEN=example-flush-token +# The maximum number of retries to be done when connecting to the Safe Client Gateway +#CGW_SESSION_MAX_RETRIES=0 + +# The request timeout in seconds for requests done to the Safe Client Gateway +#CGW_SESSION_TIMEOUT_SECONDS=2 + # What CPU and memory constraints will be added to your services? When left at # 0, they will happily use as much as needed. #DOCKER_POSTGRES_CPUS=0 diff --git a/src/clients/safe_client_gateway.py b/src/clients/safe_client_gateway.py index 0cfce38d..245d5471 100644 --- a/src/clients/safe_client_gateway.py +++ b/src/clients/safe_client_gateway.py @@ -4,6 +4,7 @@ from urllib.parse import urljoin import requests +from django.conf import settings logger = logging.getLogger(__name__) @@ -11,7 +12,9 @@ @cache def setup_session() -> requests.Session: session = requests.Session() - adapter = requests.adapters.HTTPAdapter(max_retries=3) + adapter = requests.adapters.HTTPAdapter( + max_retries=settings.CGW_SESSION_MAX_RETRIES + ) session.mount("http://", adapter) session.mount("https://", adapter) return session @@ -33,6 +36,7 @@ def flush( url, json=json, headers={"Authorization": f"Basic {cgw_flush_token}"}, + timeout=settings.CGW_SESSION_TIMEOUT_SECONDS, ) post.raise_for_status() except Exception as error: diff --git a/src/config/settings.py b/src/config/settings.py index e1b6e044..26ea934b 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -201,6 +201,8 @@ CGW_URL = os.environ.get("CGW_URL") CGW_FLUSH_TOKEN = os.environ.get("CGW_FLUSH_TOKEN") +CGW_SESSION_MAX_RETRIES = int(os.environ.get("CGW_SESSION_MAX_RETRIES", "0")) +CGW_SESSION_TIMEOUT_SECONDS = int(os.environ.get("CGW_SESSION_TIMEOUT_SECONDS", "2")) # By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. # (using the default the default FileSystemStorage)