Repository navigation
feat(python-client): retry a GET on 429 and 502-504 with exponential backoff #12513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rubenfiszel
merged 6 commits into
windmill-labs:main
from
burrows99:feat/client-retry-backoff
Nov 19, 2026
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef6e7b8
feat(python-client): retry a GET on 429 and 502-504 with exponential …
burrows99 5c69a24
fix(python-client): honour an HTTP-date Retry-After and test the 502/…
burrows99 dcf66c0
Merge branch 'main' into feat/client-retry-backoff
burrows99 fe934c9
Merge remote-tracking branch 'origin/main' into pr-12513
rubenfiszel 2824541
fix(python-client): never repeat the slack approval GET and bound GET…
rubenfiszel 4a7ffd1
fix(python-client): fall back to the backoff delay on a Retry-After d…
burrows99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Windmill.get retries a GET the server rejected under load, with backoff.""" | ||
|
|
||
| import httpx | ||
| import pytest | ||
|
|
||
| from wmill.client import Windmill | ||
|
|
||
|
|
||
| def _client(statuses, monkeypatch): | ||
| sent, sleeps = [], [] | ||
| responses = iter(statuses) | ||
|
|
||
| def handler(request: httpx.Request) -> httpx.Response: | ||
| sent.append(request) | ||
| status, headers = next(responses) | ||
| return httpx.Response(status, headers=headers, json="value") | ||
|
|
||
| monkeypatch.setattr("wmill.client.time.sleep", sleeps.append) | ||
| client = Windmill(base_url="http://wm.test", token="t", workspace="ws") | ||
| client.client = httpx.Client(base_url=client.base_url, transport=httpx.MockTransport(handler)) | ||
| return client, sent, sleeps | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "statuses, retry_budget, expected", | ||
| [ | ||
| ([(503, {}), (429, {"Retry-After": "5"}), (200, {})], None, (200, 3, [1, 5])), | ||
| ([(503, {})] * 4, None, (503, 4, [1, 2, 4])), | ||
| # a Retry-After past the remaining budget ends the retries | ||
| ([(502, {}), (504, {"Retry-After": "120"})], None, (504, 2, [1])), | ||
| ([(429, {"Retry-After": "10"}), (429, {"Retry-After": "10"})], None, (429, 2, [10])), | ||
| ([(503, {"Retry-After": "Fri, 01 Jan 2100 00:00:00 GMT"})], None, (503, 1, [])), | ||
| ([(503, {"Retry-After": "Wed, 21 Oct 2015 07:28:00 GMT"}), (200, {})], None, (200, 2, [0])), | ||
| ([(503, {})] * 3, 3, (503, 3, [1, 2])), | ||
| ([(404, {})], None, (404, 1, [])), | ||
| ([(200, {})], None, (200, 1, [])), | ||
| ], | ||
| ) | ||
| def test_get_retries_transient_errors(statuses, retry_budget, expected, monkeypatch): | ||
| client, sent, sleeps = _client(statuses, monkeypatch) | ||
| resp = client.get( | ||
| "/w/ws/variables/get_value/u/a/b", raise_for_status=False, retry_budget=retry_budget | ||
| ) | ||
| assert (resp.status_code, len(sent), sleeps) == expected | ||
|
|
||
|
|
||
| def test_slack_approval_request_is_not_repeated(monkeypatch): | ||
| # the endpoint posts the approval message: a proxy 502 after it did must not post a second | ||
| client, sent, sleeps = _client([(502, {}), (200, {})], monkeypatch) | ||
| monkeypatch.setenv("WM_JOB_ID", "job") | ||
| monkeypatch.setenv("WM_FLOW_JOB_ID", "flow") | ||
| with pytest.raises(Exception): | ||
| client.request_interactive_slack_approval("u/a/slack", "C1") | ||
| assert (len(sent), sleeps) == (1, []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.