8000 feat(client): make retries configurable in GraphQL · python-gitlab/python-gitlab@145870e · GitHub
[go: up one dir, main page]

Skip to content

Commit 145870e

Browse files
nejchmax-wittig
authored andcommitted
feat(client): make retries configurable in GraphQL
1 parent 8898c38 commit 145870e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

gitlab/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,9 @@ def __init__(
12871287
timeout: Optional[float] = None,
12881288
user_agent: str = gitlab.const.USER_AGENT,
12891289
fetch_schema_from_transport: bool = False,
1290+
max_retries: int = 10,
1291+
obey_rate_limit: bool = True,
1292+
retry_transient_errors: bool = False,
12901293
) -> None:
12911294
if not _GQL_INSTALLED:
12921295
raise ImportError(
@@ -1300,6 +1303,9 @@ def __init__(
13001303
self._url = f"{self._base_url}/api/graphql"
13011304
self._user_agent = user_agent
13021305
self._ssl_verify = ssl_verify
1306+
self._max_retries = max_retries
1307+
self._obey_rate_limit = obey_rate_limit
1308+
self._retry_transient_errors = retry_transient_errors
13031309

13041310
opts = self._get_client_opts()
13051311
self._http_client = client or httpx.Client(**opts)
@@ -1333,7 +1339,9 @@ def execute(
13331339
) -> Any:
13341340
parsed_document = self._gql(request)
13351341
retry = utils.Retry(
1336-
max_retries=3, obey_rate_limit=True, retry_transient_errors=False
1342+
max_retries=self._max_retries,
1343+
obey_rate_limit=self._obey_rate_limit,
1344+
retry_transient_errors=self._retry_transient_errors,
13371345
)
13381346

13391347
while True:

tests/unit/test_graphql.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ def test_graphql_retries_on_429_response(
3535
gl_gql.execute("query {currentUser {id}}")
3636

3737

38-
def test_graphql_raises_when_max_retries_exceeded(
39-
gl_gql: gitlab.GraphQL, respx_mock: respx.MockRouter
40-
):
38+
def test_graphql_raises_when_max_retries_exceeded(respx_mock: respx.MockRouter):
4139
url = "https://gitlab.example.com/api/graphql"
4240
responses = [
4341
httpx.Response(502),
4442
httpx.Response(502),
4543
httpx.Response(502),
46-
httpx.Response(502),
47-
httpx.Response(502),
4844
]
4945
respx_mock.post(url).mock(side_effect=responses)
46+
47+
gl_gql = gitlab.GraphQL(
48+
"https://gitlab.example.com", max_retries=1, retry_transient_errors=True
49+
)
5050
with pytest.raises(gitlab.GitlabHttpError):
5151
gl_gql.execute("query {currentUser {id}}")
5252

0 commit comments

Comments
 (0)
0