From fb78a6e98e972dfccd7b367810f26d68d743e088 Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Wed, 6 Jan 2021 12:29:24 +0100 Subject: [PATCH] Retry ILIAS downloads a few times and only fail that file --- PFERD/ilias/downloader.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/PFERD/ilias/downloader.py b/PFERD/ilias/downloader.py index 82527a0..26e1f2d 100644 --- a/PFERD/ilias/downloader.py +++ b/PFERD/ilias/downloader.py @@ -122,9 +122,22 @@ class IliasDownloader: tmp_file = self._tmp_dir.new_path() - while not self._try_download(info, tmp_file): - LOGGER.info("Retrying download: %r", info) - self._authenticator.authenticate(self._session) + download_successful = False + for _ in range(0, 3): + try: + if not self._try_download(info, tmp_file): + LOGGER.info("Re-Authenticating due to download failure: %r", info) + self._authenticator.authenticate(self._session) + else: + download_successful = True + break + except IOError as e: + PRETTY.warning(f"I/O Error when downloading ({e}). Retrying...",) + LOGGER.info("Retrying download for %s", info.path) + + if not download_successful: + PRETTY.error(f"Download of file {info.path} failed too often! Skipping it...") + return dst_path = self._organizer.accept_file(tmp_file, info.path) if dst_path and info.modification_date: