Skip to content

Commit

Permalink
Merge pull request #96 from robhudson/apiclient-retries
Browse files Browse the repository at this point in the history
Add retries to the APIClient session
  • Loading branch information
clouserw authored Feb 28, 2024
2 parents 6c3f803 + e606dee commit 96d4dde
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fxa/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import requests.auth
import requests.utils
import hawkauthlib
from requests.adapters import HTTPAdapter
from urllib3.util import Retry

import fxa
import fxa.errors
Expand Down Expand Up @@ -157,6 +159,13 @@ class APIClient(object):
def __init__(self, server_url, session=None):
if session is None:
session = requests.Session()
# Mount an HTTPAdapter to retry requests.
retries = Retry(
total=3,
backoff_factor=0.5,
allowed_methods={"DELETE", "GET", "POST", "PUT"},
)
session.mount(server_url, HTTPAdapter(max_retries=retries))
# Properties that can be customized to change behaviour.
self.server_url = server_url
self.timeout = 30
Expand Down

0 comments on commit 96d4dde

Please sign in to comment.