Skip to content

Commit ec24af3

Browse files
author
Zach Banks
committed
MOD: More aggressive retry logic in batch.download
1 parent 6cf45e5 commit ec24af3

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

databento/historical/api/batch.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
logger = logging.getLogger(__name__)
4949

50-
BATCH_DOWNLOAD_MAX_RETRIES: Final = 3
50+
BATCH_DOWNLOAD_MAX_RETRIES: Final = 5
5151

5252

5353
class BatchHttpAPI(BentoHttpAPI):
@@ -457,6 +457,11 @@ def _download_batch_file(
457457
with open(output_path, mode=mode) as f:
458458
for chunk in response.iter_content(chunk_size=HTTP_STREAMING_READ_SIZE):
459459
f.write(chunk)
460+
461+
# Successfully wrote some data, reset attempts counter
462+
if attempts > 0:
463+
attempts = 0
464+
logger.info(f"Resumed download of {output_path.name}.")
460465
except BentoHttpError as exc:
461466
if exc.http_status == 429:
462467
wait_time = int(exc.headers.get("Retry-After", 1))
@@ -465,10 +470,11 @@ def _download_batch_file(
465470
raise
466471
except Exception as exc:
467472
if attempts < BATCH_DOWNLOAD_MAX_RETRIES:
473+
attempts += 1
468474
logger.error(
469-
f"Retrying download of {output_path.name} due to error: {exc}",
475+
f"Retrying download of {output_path.name} due to error, "
476+
f"{attempts}/{BATCH_DOWNLOAD_MAX_RETRIES}: {exc}",
470477
)
471-
attempts += 1
472478
continue # try again
473479
raise BentoError(f"Error downloading file: {exc}") from None
474480
else:

0 commit comments

Comments
 (0)