From 800f35c725ff22202f211fcc86a01e6ac77a7d45 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:22:08 -0500 Subject: [PATCH] fix(codecov): add retry logic to codecov collection --- src/updater.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/updater.py b/src/updater.py index c43b7533..d82ea08c 100644 --- a/src/updater.py +++ b/src/updater.py @@ -1,6 +1,7 @@ # standard imports import os from threading import Thread +import time # lib imports from crowdin_api import CrowdinClient @@ -44,8 +45,20 @@ def update_codecov(): url = f'{base_url}/repos?page_size=500' - response = helpers.s.get(url=url, headers=headers) - data = response.json() + max_tries = 5 + count = 0 + data = None + response = None + while count < max_tries: + response = helpers.s.get(url=url, headers=headers) + try: + data = response.json() + except requests.exceptions.JSONDecodeError: + count += 1 + time.sleep(2 ** count) # exponential backoff + + if not data: + raise requests.exceptions.HTTPError(f'Error: {response.text}') if response.status_code != 200: raise requests.exceptions.HTTPError(f'Error: {data["detail"]}')