mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-08 20:25:30 +00:00
feat(scan): tolerate add entity failed
This commit is contained in:
parent
2d770c0afb
commit
58ab45c100
@ -357,6 +357,10 @@ async def add_entity(
|
|||||||
new_entity,
|
new_entity,
|
||||||
) -> Tuple[FileStatus, bool, httpx.Response]:
|
) -> Tuple[FileStatus, bool, httpx.Response]:
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
|
MAX_RETRIES = 3
|
||||||
|
RETRY_DELAY = 2.0
|
||||||
|
for attempt in range(MAX_RETRIES):
|
||||||
|
try:
|
||||||
post_response = await client.post(
|
post_response = await client.post(
|
||||||
f"{BASE_URL}/libraries/{library_id}/entities",
|
f"{BASE_URL}/libraries/{library_id}/entities",
|
||||||
json=new_entity,
|
json=new_entity,
|
||||||
@ -366,7 +370,20 @@ async def add_entity(
|
|||||||
if 200 <= post_response.status_code < 300:
|
if 200 <= post_response.status_code < 300:
|
||||||
return new_entity["filepath"], FileStatus.ADDED, True, post_response
|
return new_entity["filepath"], FileStatus.ADDED, True, post_response
|
||||||
else:
|
else:
|
||||||
return new_entity["filepath"], FileStatus.ADDED, False, post_response
|
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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user