279ae684ea
- Move pipeline.py, schemas.py, config.py, state.py, errors.py - Move retry.py, idempotency.py, link_parser.py - Create pipeline/__init__.py with updated imports - Update all internal imports to use kb_workflow.pipeline prefix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
"""Retry mechanism for KB Pipeline
|
|
|
|
Provides automatic retry for network errors using tenacity library.
|
|
"""
|
|
|
|
import logging
|
|
from tenacity import (
|
|
retry,
|
|
stop_after_attempt,
|
|
wait_exponential,
|
|
retry_if_exception_type,
|
|
before_sleep_log,
|
|
)
|
|
|
|
from .errors import NetworkError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
retry_on_network_error = retry(
|
|
stop=stop_after_attempt(3),
|
|
wait=wait_exponential(multiplier=1, min=2, max=10),
|
|
retry=retry_if_exception_type(NetworkError),
|
|
before_sleep=before_sleep_log(logger, logging.WARNING),
|
|
reraise=True,
|
|
)
|
|
"""Decorator for automatic retry on network errors
|
|
|
|
Automatically retries functions that raise NetworkError up to 3 times
|
|
with exponential backoff (2s, 4s, up to max 10s).
|
|
|
|
Example:
|
|
@retry_on_network_error
|
|
def fetch_data(url):
|
|
response = requests.get(url)
|
|
if response.status_code >= 500:
|
|
raise NetworkError(
|
|
step_name="fetch",
|
|
input_summary=f"url={url}",
|
|
status_code=response.status_code
|
|
)
|
|
return response.json()
|
|
|
|
Args:
|
|
func: Function to wrap with retry logic
|
|
|
|
Returns:
|
|
Wrapped function with retry logic
|
|
|
|
Raises:
|
|
NetworkError: After 3 failed attempts
|
|
"""
|