Skip to content

Commit

Permalink
Retry mechanism for builders to keep trying when webs are overloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Nov 14, 2018
1 parent 4fa2746 commit f80fb1e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion readthedocs/restapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import requests
from django.conf import settings
from requests.packages.urllib3.util.retry import Retry
from requests_toolbelt.adapters import host_header_ssl
from rest_framework.renderers import JSONRenderer
from slumber import API, serialize
Expand Down Expand Up @@ -44,9 +45,21 @@ def setup_api():
else:
adapter_class = requests.adapters.HTTPAdapter

# Define a retry mechanism trying to attempt to not fail in the first
# error. Builders hit this issue frequently because the webs are high loaded
retry = Retry(
total=3,
read=3,
connect=3,
status=3,
backoff_factor=0.5, # 0.5, 1, 2 seconds
method_whitelist=('GET', 'PUT', 'PATCH'),
status_forcelist=(408, 500, 502, 503, 504),
)

session.mount(
API_HOST,
adapter_class(max_retries=3),
adapter_class(max_retries=retry),
)
session.headers.update({'Host': PRODUCTION_DOMAIN})
api_config = {
Expand Down

0 comments on commit f80fb1e

Please sign in to comment.