From e5484f0a6d988dab9772665ef2bc9cb7f7aef5c9 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 6 Feb 2023 02:01:53 +0300 Subject: [PATCH] More attempts for federate --- src/fw_api.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/fw_api.py b/src/fw_api.py index ade8592..4fd2f7a 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -6,6 +6,7 @@ import urllib.parse import os from loguru import logger +attempts_for_federate = 3 auth_file = '.auth.json' if os.path.exists(auth_file): with open('.auth.json', 'rt') as f: @@ -255,8 +256,15 @@ def federate_search_by_url(object): params = { 'object': object } - r = current_instance.s.post( - f'https://{current_instance.instance}/api/v1/federation/fetches', json=params) + for i in range(attempts_for_federate): + try: + r = current_instance.s.post( + f'https://{current_instance.instance}/api/v1/federation/fetches', json=params) + r.raise_for_status() + break + except Exception as Err: + logger.error(f'Attempt {i}: {Err}') + time.sleep(3) return r.json() @@ -266,16 +274,30 @@ def federate_remote_library(fid): params = { 'fid': fid } - r = current_instance.s.post( - f'https://{current_instance.instance}/api/v1/federation/libraries/fetch', json=params) + for i in range(attempts_for_federate): + try: + r = current_instance.s.post( + f'https://{current_instance.instance}/api/v1/federation/libraries/fetch', json=params) + r.raise_for_status() + break + except Exception as Err: + logger.error(f'Attempt {i}: {Err}') + time.sleep(3) return r.json() @logger.catch def scan_remote_library(uuid): '''Scan remote library''' - r = current_instance.s.post( - f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}') + for i in range(attempts_for_federate): + try: + r = current_instance.s.post( + f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}') + r.raise_for_status() + break + except Exception as Err: + logger.error(f'Attempt {i}: {Err}') + time.sleep(3) return r.json()