More attempts for federate

This commit is contained in:
localhost_frssoft 2023-02-06 02:01:53 +03:00
parent 74b5f59684
commit e5484f0a6d

View file

@ -6,6 +6,7 @@ import urllib.parse
import os import os
from loguru import logger from loguru import logger
attempts_for_federate = 3
auth_file = '.auth.json' auth_file = '.auth.json'
if os.path.exists(auth_file): if os.path.exists(auth_file):
with open('.auth.json', 'rt') as f: with open('.auth.json', 'rt') as f:
@ -255,8 +256,15 @@ def federate_search_by_url(object):
params = { params = {
'object': object 'object': object
} }
for i in range(attempts_for_federate):
try:
r = current_instance.s.post( r = current_instance.s.post(
f'https://{current_instance.instance}/api/v1/federation/fetches', json=params) 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() return r.json()
@ -266,16 +274,30 @@ def federate_remote_library(fid):
params = { params = {
'fid': fid 'fid': fid
} }
for i in range(attempts_for_federate):
try:
r = current_instance.s.post( r = current_instance.s.post(
f'https://{current_instance.instance}/api/v1/federation/libraries/fetch', json=params) 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() return r.json()
@logger.catch @logger.catch
def scan_remote_library(uuid): def scan_remote_library(uuid):
'''Scan remote library''' '''Scan remote library'''
for i in range(attempts_for_federate):
try:
r = current_instance.s.post( r = current_instance.s.post(
f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}') 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() return r.json()