Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.3.0

* Fix typing error ([#15](https://github.com/austind/retryhttp/pull/15))
* Add default fallback wait strategy [`tenacity.wait_random_exponential`][] to [`retryhttp.wait_from_header`][] and [`retryhttp.wait_retry_after`][] ([#17](https://github.com/austind/retryhttp/pull/))

## v1.2.0

* Added `wait_max` argument to [`retryhttp.wait_from_header`][] and [`retryhttp.wait_retry_after`][], which defaults to 120.0 seconds.
Expand Down
12 changes: 7 additions & 5 deletions retryhttp/_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class wait_from_header(wait_base):
program will hang if the server responds with an excessive wait value.
fallback (wait_base): Wait strategy to use if `header` is not present,
or unable to parse to a `float` value, or if value parsed from header
exceeds `wait_max`. Defaults to `None`.
exceeds `wait_max`. Defaults to `tenacity.wait_exponential`.

Raises:
ValueError: If `fallback` is `None`, and any one of the following is true:
Expand All @@ -47,7 +47,7 @@ def __init__(
self,
header: str,
wait_max: Union[PositiveFloat, PositiveInt, None] = 120.0,
fallback: Optional[wait_base] = None,
fallback: Optional[wait_base] = wait_exponential(),
) -> None:
self.header = header
self.wait_max = float(wait_max) if wait_max else None
Expand All @@ -69,7 +69,9 @@ def _get_wait_value(self, retry_state: RetryCallState) -> float:
if retry_state.outcome:
exc = retry_state.outcome.exception()
if isinstance(exc, get_default_http_status_exceptions()):
value = exc.response.headers.get(self.header, "")
value = exc.response.headers.get(self.header)
if value is None:
raise ValueError(f"Header not present: {self.header}")
if re.match(r"^\d+$", value):
return float(value)
else:
Expand Down Expand Up @@ -115,7 +117,7 @@ class wait_retry_after(wait_from_header):
program will hang if the server responds with an excessive wait value.
fallback (wait_base): Wait strategy to use if `header` is not present,
or unable to parse to a `float` value, or if value parsed from header
exceeds `wait_max`. Defaults to `None`.
exceeds `wait_max`. Defaults to `tenacity.wait_exponential()`.

Raises:
ValueError: If `fallback` is `None`, and any one of the following is true:
Expand All @@ -129,7 +131,7 @@ class wait_retry_after(wait_from_header):
def __init__(
self,
wait_max: Union[PositiveFloat, PositiveInt, None] = 120.0,
fallback: Optional[wait_base] = None,
fallback: Optional[wait_base] = wait_exponential(),
) -> None:
super().__init__(header="Retry-After", wait_max=wait_max, fallback=fallback)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@retry(
retry=retry_if_server_error(),
wait=wait_from_header(header="Retry-After", wait_max=5),
wait=wait_from_header(header="Retry-After", wait_max=5, fallback=None),
stop=stop_after_attempt(3),
)
def planned_downtime_impatient_no_fallback():
Expand Down