Skip to content

Commit

Permalink
Merge pull request #235 from preset-io/session_retry
Browse files Browse the repository at this point in the history
fix(session): Implement retry mechanism for closed connections
  • Loading branch information
Vitor-Avila authored Aug 21, 2023
2 parents 9443edb + 6ea358f commit 2d6107f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/preset_cli/auth/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Any, Dict

from requests import Response, Session
from requests.adapters import HTTPAdapter
from urllib3.util import Retry


class Auth: # pylint: disable=too-few-public-methods
Expand All @@ -16,6 +18,14 @@ def __init__(self):
self.session = Session()
self.session.hooks["response"].append(self.reauth)

retries = Retry(
total=3, # max retries count
backoff_factor=1, # delay factor between attempts
respect_retry_after_header=True,
)

self.session.mount("https://", HTTPAdapter(max_retries=retries))

def get_headers(self) -> Dict[str, str]:
"""
Return headers for auth.
Expand Down

0 comments on commit 2d6107f

Please sign in to comment.