fix/ci-deploy-reset #9

Merged
starmen1265 merged 96 commits from fix/ci-deploy-reset into main 2026-03-15 01:05:14 +08:00
Showing only changes of commit 74adaf3a79 - Show all commits
+51
View File
@@ -0,0 +1,51 @@
"""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
"""