Add a retry when getting data from gerrit
Borrowed from openstack-infra/system-config:tools/owners.py Change-Id: I7526d03838567ed5d916ed8165e52b1d62f5ccc6
This commit is contained in:
parent
735c6fb313
commit
6aca611e32
@ -45,6 +45,15 @@ exceptions = None
|
|||||||
|
|
||||||
|
|
||||||
# Generic functions
|
# Generic functions
|
||||||
|
def requester(url, params={}, headers={}):
|
||||||
|
"""A requests wrapper to consistently retry HTTPS queries"""
|
||||||
|
|
||||||
|
# Try up to 3 times
|
||||||
|
retry = requests.Session()
|
||||||
|
retry.mount("https://", requests.adapters.HTTPAdapter(max_retries=3))
|
||||||
|
return retry.get(url=url, params=params, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
def load_exceptions():
|
def load_exceptions():
|
||||||
global exceptions
|
global exceptions
|
||||||
exceptions = {}
|
exceptions = {}
|
||||||
@ -67,7 +76,7 @@ def gerrit_datetime(dt):
|
|||||||
|
|
||||||
|
|
||||||
def gerrit_query(url, params=None):
|
def gerrit_query(url, params=None):
|
||||||
r = requests.get(url, params=params)
|
r = requester(url, params=params)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
data = json.loads(r.text[4:])
|
data = json.loads(r.text[4:])
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user