Skip to content

Commit

Permalink
Add retry on GET requests to QFieldCloud API
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jul 28, 2023
1 parent e0655df commit c470b6a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qfieldcloud_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from qfieldcloud_sdk.interfaces import QfcException, QfcRequest, QfcRequestException
from qfieldcloud_sdk.utils import get_numeric_params, log
from requests.adapters import HTTPAdapter, Retry

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -54,6 +55,16 @@ def __init__(
`session` will be reused between requests if the SDK is run as a library.
"""
self.session = requests.Session()
# retries should be only on GET and only if error 5xx
retries = Retry(
total=5,
backoff_factor=0.1,
allowed_methods=["GET"],
# skip 501, as it is "Not Implemented", no point to retry
status_forcelist=[500, 502, 503, 504],
)
self.session.mount("https://", HTTPAdapter(max_retries=retries))

self.url = url or os.environ.get("QFIELDCLOUD_URL", None)
self.token = token or os.environ.get("QFIELDCLOUD_TOKEN", None)
self.verify_ssl = verify_ssl
Expand Down

0 comments on commit c470b6a

Please sign in to comment.