Support NETWORK_ALWAYS_ERROR on downloads

This commit is contained in:
Sumner Evans
2020-05-27 00:11:03 -06:00
parent 1bba10b37c
commit 420ad79c24
2 changed files with 9 additions and 2 deletions

View File

@@ -59,6 +59,10 @@ if delay_str := os.environ.get("REQUEST_DELAY"):
else:
REQUEST_DELAY = (float(delay_str), float(delay_str))
NETWORK_ALWAYS_ERROR: bool = False
if always_error := os.environ.get("NETWORK_ALWAYS_ERROR"):
NETWORK_ALWAYS_ERROR = True
T = TypeVar("T")
@@ -383,10 +387,13 @@ class AdapterManager:
if REQUEST_DELAY is not None:
delay = random.uniform(*REQUEST_DELAY)
logging.info(
f"REQUEST_DELAY enabled. Pausing for {delay} seconds" # noqa: E501
f"REQUEST_DELAY enabled. Pausing for {delay} seconds"
)
sleep(delay)
if NETWORK_ALWAYS_ERROR:
raise Exception("NETWORK_ALWAYS_ERROR enabled")
data = requests.get(uri)
# TODO (#122): make better

View File

@@ -246,7 +246,7 @@ class SubsonicAdapter(Adapter):
params = {**self._get_params(), **params}
logging.info(f"[START] get: {url}")
if REQUEST_DELAY:
if REQUEST_DELAY is not None:
delay = random.uniform(*REQUEST_DELAY)
logging.info(f"REQUEST_DELAY enabled. Pausing for {delay} seconds")
sleep(delay)