refactor: apply SSL retry decorator to all tool modules

This commit is contained in:
Jihun Kim
2025-07-14 15:08:03 +01:00
parent 6a32a411f9
commit a92748b947
11 changed files with 498 additions and 32 deletions

View File

@@ -3,11 +3,37 @@ import logging
import os
import tempfile
import zipfile, xml.etree.ElementTree as ET
import ssl
import time
import asyncio
import functools
from typing import List, Optional
logger = logging.getLogger(__name__)
def retry_on_ssl_error(max_retries=3, base_delay=1):
"""
A decorator to retry a function call on ssl.SSLError with exponential backoff.
"""
def decorator(func):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
for attempt in range(max_retries):
try:
return await func(*args, **kwargs)
except ssl.SSLError as e:
if attempt < max_retries - 1:
delay = base_delay * (2 ** attempt)
logger.warning(f"SSL error in {func.__name__} on attempt {attempt + 1}: {e}. Retrying in {delay} seconds...")
await asyncio.sleep(delay)
else:
logger.error(f"SSL error in {func.__name__} on final attempt: {e}. Raising exception.")
raise
return wrapper
return decorator
def check_credentials_directory_permissions(credentials_dir: str = None) -> None:
"""
Check if the service has appropriate permissions to create and write to the .credentials directory.