summaryrefslogtreecommitdiff
path: root/gitlab/client.py
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-12-05 21:48:07 +0100
committerNejc Habjan <hab.nejc@gmail.com>2022-12-19 22:58:03 +0100
commit3e1c625133074ccd2fb88c429ea151bfda96aebb (patch)
treea63af76909e9d322b9d2899a34cf68b4a514455f /gitlab/client.py
parentdced76a9900c626c9f0b90b85a5e371101a24fb4 (diff)
downloadgitlab-3e1c625133074ccd2fb88c429ea151bfda96aebb.tar.gz
chore: add test, docs, and helper for 409 retries
Diffstat (limited to 'gitlab/client.py')
-rw-r--r--gitlab/client.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/gitlab/client.py b/gitlab/client.py
index f9462ba..ffdfadf 100644
--- a/gitlab/client.py
+++ b/gitlab/client.py
@@ -751,13 +751,20 @@ class Gitlab:
if 200 <= result.status_code < 300:
return result.response
- if (429 == result.status_code and obey_rate_limit) or (
- (
- result.status_code in gitlab.const.RETRYABLE_TRANSIENT_ERROR_CODES
- or (result.status_code == 409 and "Resource lock" in result.reason)
- )
- and retry_transient_errors
- ):
+ def should_retry() -> bool:
+ if result.status_code == 429 and obey_rate_limit:
+ return True
+
+ if not retry_transient_errors:
+ return False
+ if result.status_code in gitlab.const.RETRYABLE_TRANSIENT_ERROR_CODES:
+ return True
+ if result.status_code == 409 and "Resource lock" in result.reason:
+ return True
+
+ return False
+
+ if should_retry():
# Response headers documentation:
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
if max_retries == -1 or cur_retries < max_retries: