From 5103f1bd0e43b7fc20a1f5eb5ba10d63f1dd7b68 Mon Sep 17 00:00:00 2001 From: ZhymabekRoman Date: Sat, 9 Mar 2024 10:35:22 +0500 Subject: [PATCH] Fixing sleep time on retry --- core/medium_parser/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/medium_parser/core.py b/core/medium_parser/core.py index c805201..cf61f9d 100644 --- a/core/medium_parser/core.py +++ b/core/medium_parser/core.py @@ -102,17 +102,13 @@ class MediumParser: post_data, is_cache_used = None, False attempt = 0 + reason = None while not post_data and attempt < retry: try: post_data, is_cache_used = await self.query_get(use_cache) except Exception as e: logger.error(f"Attempt {attempt + 1} failed with exception: {e}") - finally: - logger.info(f"Retrying in {2 ** attempt} seconds...") - await asyncio.sleep(2 ** attempt) - attempt += 1 - - reason = None + continue if not post_data: reason = "No post data returned" @@ -127,6 +123,10 @@ class MediumParser: if reason is None: break + + logger.info(f"Retrying in {2 ** attempt} seconds...") + await asyncio.sleep(2 ** attempt) + attempt += 1 else: if not reason: reason = "Unknown"