From 07d9883c15135b73a13c62e1f0e90122c2646c0b Mon Sep 17 00:00:00 2001 From: ZhymabekRoman Date: Sat, 9 Mar 2024 20:37:08 +0500 Subject: [PATCH] Fixing sleep time --- core/medium_parser/core.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core/medium_parser/core.py b/core/medium_parser/core.py index cf61f9d..3212437 100644 --- a/core/medium_parser/core.py +++ b/core/medium_parser/core.py @@ -106,27 +106,26 @@ class MediumParser: while not post_data and attempt < retry: try: post_data, is_cache_used = await self.query_get(use_cache) + + if not post_data: + reason = "No post data returned" + elif not isinstance(post_data, dict): + reason = "Post data is not a dictionary" + elif post_data.get("error"): + reason = "Post data contains an error" + elif not post_data.get("data"): + reason = "Post data missing 'data' key" + elif not post_data.get("data").get("post"): + reason = "Post data missing 'data.post' key" + + if reason is None: + break except Exception as e: logger.error(f"Attempt {attempt + 1} failed with exception: {e}") - continue - - if not post_data: - reason = "No post data returned" - elif not isinstance(post_data, dict): - reason = "Post data is not a dictionary" - elif post_data.get("error"): - reason = "Post data contains an error" - elif not post_data.get("data"): - reason = "Post data missing 'data' key" - elif not post_data.get("data").get("post"): - reason = "Post data missing 'data.post' key" - - if reason is None: - break - - logger.info(f"Retrying in {2 ** attempt} seconds...") - await asyncio.sleep(2 ** attempt) - attempt += 1 + finally: + logger.info(f"Retrying in {2 ** attempt} seconds...") + await asyncio.sleep(2 ** attempt) + attempt += 1 else: if not reason: reason = "Unknown"