| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -348,3 +348,21 @@ throttled, you can set this parameter to -1. This parameter is ignored if | |||
| 348 | 348 | .. warning:: | |
| 349 | 349 | ||
| 350 | 350 | You will get an Exception, if you then go over the rate limit of your GitLab instance. | |
| 351 | + | ||
| 352 | + Transient errors | ||
| 353 | + ---------------- | ||
| 354 | + | ||
| 355 | + GitLab server can sometimes return a transient HTTP error. | ||
| 356 | + python-gitlab can automatically retry in such case, when | ||
| 357 | + ``retry_transient_errors`` argument is set to ``True``. When enabled, | ||
| 358 | + HTTP error codes 500 (Internal Server Error), 502 (502 Bad Gateway), | ||
| 359 | + 503 (Service Unavailable), and 504 (Gateway Timeout) are retried. By | ||
| 360 | + default an exception is raised for these errors. | ||
| 361 | + | ||
| 362 | + .. code-block:: python | ||
| 363 | + | ||
| 364 | + import gitlab | ||
| 365 | + import requests | ||
| 366 | + | ||
| 367 | + gl = gitlab.gitlab(url, token, api_version=4) | ||
| 368 | + gl.projects.list(all=True, retry_transient_errors=True) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -518,6 +518,8 @@ def http_request( | |||
| 518 | 518 | ||
| 519 | 519 | # obey the rate limit by default | |
| 520 | 520 | obey_rate_limit = kwargs.get("obey_rate_limit", True) | |
| 521 | + # do not retry transient errors by default | ||
| 522 | + retry_transient_errors = kwargs.get("retry_transient_errors", False) | ||
| 521 | 523 | ||
| 522 | 524 | # set max_retries to 10 by default, disable by setting it to -1 | |
| 523 | 525 | max_retries = kwargs.get("max_retries", 10) | |
@@ -531,7 +533,9 @@ def http_request( | |||
| 531 | 533 | if 200 <= result.status_code < 300: | |
| 532 | 534 | return result | |
| 533 | 535 | ||
| 534 | - if 429 == result.status_code and obey_rate_limit: | ||
| 536 | + if (429 == result.status_code and obey_rate_limit) or ( | ||
| 537 | + result.status_code in [500, 502, 503, 504] and retry_transient_errors | ||
| 538 | + ): | ||
| 535 | 539 | if max_retries == -1 or cur_retries < max_retries: | |
| 536 | 540 | wait_time = 2 ** cur_retries * 0.1 | |
| 537 | 541 | if "Retry-After" in result.headers: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments