feat(scan): tolerate add entity failed

This commit is contained in:
arkohut 2024-07-29 19:18:28 +08:00
parent 2d770c0afb
commit 58ab45c100

View File

@ -357,16 +357,33 @@ async def add_entity(
new_entity, new_entity,
) -> Tuple[FileStatus, bool, httpx.Response]: ) -> Tuple[FileStatus, bool, httpx.Response]:
async with semaphore: async with semaphore:
post_response = await client.post( MAX_RETRIES = 3
f"{BASE_URL}/libraries/{library_id}/entities", RETRY_DELAY = 2.0
json=new_entity, for attempt in range(MAX_RETRIES):
params={"plugins": plugins} if plugins else {}, try:
timeout=60, post_response = await client.post(
) f"{BASE_URL}/libraries/{library_id}/entities",
if 200 <= post_response.status_code < 300: json=new_entity,
return new_entity["filepath"], FileStatus.ADDED, True, post_response params={"plugins": plugins} if plugins else {},
else: timeout=60,
return new_entity["filepath"], FileStatus.ADDED, False, post_response )
if 200 <= post_response.status_code < 300:
return new_entity["filepath"], FileStatus.ADDED, True, post_response
else:
return (
new_entity["filepath"],
FileStatus.ADDED,
False,
post_response,
)
except Exception as e:
logging.error(
f"Error while adding entity (attempt {attempt + 1}/{MAX_RETRIES}): {e}"
)
if attempt < MAX_RETRIES - 1:
await asyncio.sleep(RETRY_DELAY)
else:
return new_entity["filepath"], FileStatus.ADDED, False, None
async def update_entity( async def update_entity(