Skip to content

Commit 5782474

Browse files
committed
Retry more when proxying to astro
1 parent 98e097b commit 5782474

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

backend/custom_admin/views.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from urllib.parse import urlparse
77
from django.http import QueryDict
88
from django.conf import settings
9+
from urllib3.util import Retry
10+
from requests.adapters import HTTPAdapter
911

1012
LOCAL_ASTRO_HTTP = "http://custom-admin:3002"
1113

@@ -41,7 +43,17 @@ def astro_proxy(request, path):
4143
requests_args["headers"] = headers
4244
requests_args["params"] = params
4345

44-
response = requests.request(request.method, url, **requests_args)
46+
session = requests.Session()
47+
retry = Retry(
48+
total=5,
49+
backoff_factor=0.1,
50+
status_forcelist=(500, 502, 504),
51+
)
52+
adapter = HTTPAdapter(max_retries=retry)
53+
session.mount("http://", adapter)
54+
session.mount("https://", adapter)
55+
56+
response = session.request(request.method, url, **requests_args)
4557
content = response.content.decode("utf-8")
4658

4759
# Base path doesn't seem to be fully supported by Astro

0 commit comments

Comments
 (0)