-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* failure webhooks * deps * fix * fix --------- Co-authored-by: Josh Smith <[email protected]>
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,20 @@ | ||
import httpx | ||
from fastapi import status | ||
from tenacity import retry_if_exception | ||
|
||
|
||
class retry_if_exception_network_related(retry_if_exception): | ||
"""Retries if an exception is from a network related failure.""" | ||
|
||
def __init__(self) -> None: | ||
def predicate(exc: BaseException) -> bool: | ||
if isinstance(exc, httpx.HTTPStatusError): | ||
if exc.response.status_code == status.HTTP_429_TOO_MANY_REQUESTS: | ||
# TODO: 3rd parties may have specific retry-after headers | ||
# that we should/can respect for better performance | ||
return True | ||
elif isinstance(exc, httpx.NetworkError): | ||
return True | ||
return False | ||
|
||
super().__init__(predicate) |
This file contains 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 |
---|---|---|
|
@@ -6,4 +6,5 @@ pydantic | |
python-dotenv | ||
python-json-logger | ||
pyyaml | ||
tenacity | ||
uvicorn |