@@ -52,6 +52,8 @@ class Gitlab(object):
52
52
pagination (str): Can be set to 'keyset' to use keyset pagination
53
53
order_by (str): Set order_by globally
54
54
user_agent (str): A custom user agent to use for making HTTP requests.
55
+ retry_transient_errors (bool): Whether to retry after 500, 502, 503, or
56
+ 504 responses. Defaults to False.
55
57
"""
56
58
57
59
def __init__ (
@@ -70,6 +72,7 @@ def __init__(
70
72
pagination : Optional [str ] = None ,
71
73
order_by : Optional [str ] = None ,
72
74
user_agent : str = gitlab .const .USER_AGENT ,
75
+ retry_transient_errors : bool = False ,
73
76
) -> None :
74
77
75
78
self ._api_version = str (api_version )
@@ -79,6 +82,7 @@ def __init__(
79
82
self ._url = "%s/api/v%s" % (self ._base_url , api_version )
80
83
#: Timeout to use for requests to gitlab server
81
84
self .timeout = timeout
85
+ self .retry_transient_errors = retry_transient_errors
82
86
#: Headers that will be used in request to GitLab
83
87
self .headers = {"User-Agent" : user_agent }
84
88
@@ -511,7 +515,6 @@ def http_request(
511
515
files : Optional [Dict [str , Any ]] = None ,
512
516
timeout : Optional [float ] = None ,
513
517
obey_rate_limit : bool = True ,
514
- retry_transient_errors : bool = False ,
515
518
max_retries : int = 10 ,
516
519
** kwargs : Any ,
517
520
) -> requests .Response :
@@ -531,9 +534,6 @@ def http_request(
531
534
timeout (float): The timeout, in seconds, for the request
532
535
obey_rate_limit (bool): Whether to obey 429 Too Many Request
533
536
responses. Defaults to True.
534
- retry_transient_errors (bool): Whether to retry after 500, 502,
535
- 503, or 504 responses. Defaults
536
- to False.
537
537
max_retries (int): Max retries after 429 or transient errors,
538
538
set to -1 to retry forever. Defaults to 10.
539
539
**kwargs: Extra options to send to the server (e.g. sudo)
@@ -598,6 +598,9 @@ def http_request(
598
598
if 200 <= result .status_code < 300 :
599
599
return result
600
600
601
+ retry_transient_errors = kwargs .get (
602
+ "retry_transient_errors" , self .retry_transient_errors
603
+ )
601
604
if (429 == result .status_code and obey_rate_limit ) or (
602
605
result .status_code in [500 , 502 , 503 , 504 ] and retry_transient_errors
603
606
):
0 commit comments