Fix linting

This commit is contained in:
yangdx 2025-09-03 21:58:30 +08:00
parent 7ef2f0dff6
commit a25ce7f078

View file

@ -63,7 +63,7 @@ async def safe_vdb_operation_with_exception(
entity_name: str = "", entity_name: str = "",
max_retries: int = 3, max_retries: int = 3,
retry_delay: float = 0.2, retry_delay: float = 0.2,
logger_func: Optional[Callable] = None logger_func: Optional[Callable] = None,
) -> None: ) -> None:
""" """
Safely execute vector database operations with retry mechanism and exception handling. Safely execute vector database operations with retry mechanism and exception handling.
@ -83,26 +83,23 @@ async def safe_vdb_operation_with_exception(
Exception: When operation fails after all retry attempts Exception: When operation fails after all retry attempts
""" """
log_func = logger_func or logger.warning log_func = logger_func or logger.warning
last_exception = None
for attempt in range(max_retries): for attempt in range(max_retries):
try: try:
await operation() await operation()
return # Success, return immediately return # Success, return immediately
except Exception as e: except Exception as e:
last_exception = e if attempt >= max_retries - 1:
if attempt == max_retries - 1:
error_msg = f"VDB {operation_name} failed for {entity_name} after {max_retries} attempts: {e}" error_msg = f"VDB {operation_name} failed for {entity_name} after {max_retries} attempts: {e}"
log_func(error_msg) log_func(error_msg)
raise Exception(error_msg) from e raise Exception(error_msg) from e
else: else:
log_func(f"VDB {operation_name} attempt {attempt + 1} failed for {entity_name}: {e}, retrying...") log_func(
f"VDB {operation_name} attempt {attempt + 1} failed for {entity_name}: {e}, retrying..."
)
if retry_delay > 0: if retry_delay > 0:
await asyncio.sleep(retry_delay) await asyncio.sleep(retry_delay)
# This line should theoretically never be reached, but included for safety
raise Exception(f"Max retries exceeded for {operation_name}") from last_exception
def get_env_value( def get_env_value(
env_key: str, default: any, value_type: type = str, special_none: bool = False env_key: str, default: any, value_type: type = str, special_none: bool = False