-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve failure handling and logging (#189)
- Loading branch information
Showing
10 changed files
with
100 additions
and
115 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
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
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 |
---|---|---|
@@ -1,6 +1,33 @@ | ||
from requests import Session | ||
from typing import Any | ||
|
||
from podcast_archiver.constants import USER_AGENT | ||
from requests import PreparedRequest, Session | ||
from requests.adapters import HTTPAdapter | ||
from requests.models import Response as Response | ||
from urllib3.util import Retry | ||
|
||
from podcast_archiver.constants import REQUESTS_TIMEOUT, USER_AGENT | ||
|
||
|
||
class DefaultTimeoutHTTPAdapter(HTTPAdapter): | ||
def send( | ||
self, | ||
request: PreparedRequest, | ||
timeout: None | float | tuple[float, float] | tuple[float, None] = None, | ||
**kwargs: Any, | ||
) -> Response: | ||
return super().send(request, timeout=timeout or REQUESTS_TIMEOUT, **kwargs) | ||
|
||
|
||
_retries = Retry( | ||
total=3, | ||
connect=1, | ||
backoff_factor=0.5, | ||
status_forcelist=[500, 501, 502, 503, 504], | ||
) | ||
|
||
_adapter = DefaultTimeoutHTTPAdapter(max_retries=_retries) | ||
|
||
session = Session() | ||
session.mount("http://", _adapter) | ||
session.mount("https://", _adapter) | ||
session.headers.update({"user-agent": USER_AGENT}) |
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
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