From 3e1c625133074ccd2fb88c429ea151bfda96aebb Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Mon, 5 Dec 2022 21:48:07 +0100 Subject: chore: add test, docs, and helper for 409 retries --- gitlab/client.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'gitlab') 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: -- cgit v1.2.1