refactor: apply SSL retry decorator to all tool modules
This commit is contained in:
@@ -18,7 +18,7 @@ from mcp import types
|
||||
from fastapi import Body
|
||||
|
||||
from auth.service_decorator import require_google_service
|
||||
from core.utils import handle_http_errors
|
||||
from core.utils import handle_http_errors, retry_on_ssl_error
|
||||
from core.server import (
|
||||
GMAIL_READONLY_SCOPE,
|
||||
GMAIL_SEND_SCOPE,
|
||||
@@ -31,28 +31,6 @@ from core.server import (
|
||||
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 _extract_message_body(payload):
|
||||
"""
|
||||
Helper function to extract plain text body from a Gmail message payload.
|
||||
|
||||
Reference in New Issue
Block a user