summaryrefslogtreecommitdiff
path: root/gitlab/client.py
diff options
context:
space:
mode:
authorKarun Japhet <karun@japhet.in>2021-08-28 11:41:59 +0530
committerKarun Japhet <karun@japhet.in>2021-08-29 15:01:18 +0530
commit3b1d3a41da7e7228f3a465d06902db8af564153e (patch)
treee16d5e53efb182475c96a32ac1f2686a43ee9c19 /gitlab/client.py
parenta00ec87bdbadccaf3e3700a48cbb797fd2750107 (diff)
downloadgitlab-3b1d3a41da7e7228f3a465d06902db8af564153e.tar.gz
feat: allow global retry_transient_errors setup
`retry_transient_errors` can now be set through the Gitlab instance and global configuration Documentation for API usage has been updated and missing tests have been added.
Diffstat (limited to 'gitlab/client.py')
-rw-r--r--gitlab/client.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/gitlab/client.py b/gitlab/client.py
index ef5b0da..47fae81 100644
--- a/gitlab/client.py
+++ b/gitlab/client.py
@@ -52,6 +52,8 @@ class Gitlab(object):
pagination (str): Can be set to 'keyset' to use keyset pagination
order_by (str): Set order_by globally
user_agent (str): A custom user agent to use for making HTTP requests.
+ retry_transient_errors (bool): Whether to retry after 500, 502, 503, or
+ 504 responses. Defaults to False.
"""
def __init__(
@@ -70,6 +72,7 @@ class Gitlab(object):
pagination: Optional[str] = None,
order_by: Optional[str] = None,
user_agent: str = gitlab.const.USER_AGENT,
+ retry_transient_errors: bool = False,
) -> None:
self._api_version = str(api_version)
@@ -79,6 +82,7 @@ class Gitlab(object):
self._url = "%s/api/v%s" % (self._base_url, api_version)
#: Timeout to use for requests to gitlab server
self.timeout = timeout
+ self.retry_transient_errors = retry_transient_errors
#: Headers that will be used in request to GitLab
self.headers = {"User-Agent": user_agent}
@@ -246,6 +250,7 @@ class Gitlab(object):
pagination=config.pagination,
order_by=config.order_by,
user_agent=config.user_agent,
+ retry_transient_errors=config.retry_transient_errors,
)
def auth(self) -> None:
@@ -511,7 +516,6 @@ class Gitlab(object):
files: Optional[Dict[str, Any]] = None,
timeout: Optional[float] = None,
obey_rate_limit: bool = True,
- retry_transient_errors: bool = False,
max_retries: int = 10,
**kwargs: Any,
) -> requests.Response:
@@ -531,9 +535,6 @@ class Gitlab(object):
timeout (float): The timeout, in seconds, for the request
obey_rate_limit (bool): Whether to obey 429 Too Many Request
responses. Defaults to True.
- retry_transient_errors (bool): Whether to retry after 500, 502,
- 503, or 504 responses. Defaults
- to False.
max_retries (int): Max retries after 429 or transient errors,
set to -1 to retry forever. Defaults to 10.
**kwargs: Extra options to send to the server (e.g. sudo)
@@ -598,6 +599,9 @@ class Gitlab(object):
if 200 <= result.status_code < 300:
return result
+ retry_transient_errors = kwargs.get(
+ "retry_transient_errors", self.retry_transient_errors
+ )
if (429 == result.status_code and obey_rate_limit) or (
result.status_code in [500, 502, 503, 504] and retry_transient_errors
):