Skip to content
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

implement retries #9

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
22 changes: 21 additions & 1 deletion flareio/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from datetime import datetime
from datetime import timedelta
from flareio.exceptions import TokenError
from requests.adapters import HTTPAdapter
from urllib.parse import urljoin
from urllib.parse import urlparse
from urllib3.util import Retry

import typing as t

Expand All @@ -24,7 +26,25 @@ def __init__(

self._api_token: t.Optional[str] = None
self._api_token_exp: t.Optional[datetime] = None
self._session = session or requests.Session()
self._session = session or self._create_session()

@staticmethod
def _create_session() -> requests.Session:
session = requests.Session()
retries = Retry(
total=5,
backoff_factor=2,
status_forcelist=[429, 502, 503, 504],
allowed_methods={"GET", "POST"},
backoff_max=15,
)
session.mount(
aviau marked this conversation as resolved.
Show resolved Hide resolved
"https://",
HTTPAdapter(
max_retries=retries,
),
)
return session

def generate_token(self) -> str:
payload: t.Optional[dict] = None
Expand Down