mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-16 15:20:09 -07:00
Uniform names for retry constants
This commit is contained in:
parent
16a2a3ed3e
commit
6af5eb1ce1
@ -23,9 +23,10 @@ OAUTH_CLIENT_KEY = 'LGAO221A02'
|
|||||||
DATE_FORMAT = '%a, %d %b %Y %H:%M:%S +0000'
|
DATE_FORMAT = '%a, %d %b %Y %H:%M:%S +0000'
|
||||||
DEFAULT_COUNTRY = 'US'
|
DEFAULT_COUNTRY = 'US'
|
||||||
DEFAULT_LANGUAGE = 'en-US'
|
DEFAULT_LANGUAGE = 'en-US'
|
||||||
NUM_RETRIES = 5 # Anecdotally this seems sufficient.
|
|
||||||
BACKOFF_FACTOR = 0.5
|
RETRY_COUNT = 5 # Anecdotally this seems sufficient.
|
||||||
STATUS_FORCELIST = (502, 503, 504)
|
RETRY_FACTOR = 0.5
|
||||||
|
RETRY_STATUSES = (502, 503, 504)
|
||||||
|
|
||||||
|
|
||||||
def get_wideq_logger() -> logging.Logger:
|
def get_wideq_logger() -> logging.Logger:
|
||||||
@ -65,15 +66,17 @@ LOGGER = get_wideq_logger()
|
|||||||
|
|
||||||
|
|
||||||
def get_retry_session():
|
def get_retry_session():
|
||||||
# See https://www.peterbe.com/plog/best-practice-with-retries-with-requests
|
"""Get a Requests session that retries HTTP and HTTPS requests.
|
||||||
# for the source of this retry mechanism
|
"""
|
||||||
|
# Adapted from:
|
||||||
|
# https://www.peterbe.com/plog/best-practice-with-retries-with-requests
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
retry = Retry(
|
retry = Retry(
|
||||||
total=NUM_RETRIES,
|
total=RETRY_COUNT,
|
||||||
read=NUM_RETRIES,
|
read=RETRY_COUNT,
|
||||||
connect=NUM_RETRIES,
|
connect=RETRY_COUNT,
|
||||||
backoff_factor=BACKOFF_FACTOR,
|
backoff_factor=RETRY_FACTOR,
|
||||||
status_forcelist=STATUS_FORCELIST,
|
status_forcelist=RETRY_STATUSES,
|
||||||
)
|
)
|
||||||
adapter = HTTPAdapter(max_retries=retry)
|
adapter = HTTPAdapter(max_retries=retry)
|
||||||
session.mount('http://', adapter)
|
session.mount('http://', adapter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user