Skip to content

Conversation

@LifeJiggy
Copy link

🔄 Add Comprehensive Retry Configuration for Improved Reliability

This PR introduces intelligent, configurable retry logic to the pydo client, making it significantly more resilient to network issues and temporary server errors.


🛠️ Problem Solved

Previously, users had to implement their own retry logic or handle transient failures manually. The client would fail immediately on network timeouts, server errors, or rate limits.


🚀 Solution

  • Smart Defaults: Automatic retries for common recoverable errors (429, 500, 502, 503, 504).
  • Configurable Parameters: Easily customize retry behavior to suit your needs.
  • Exponential Backoff: Intelligent delay increases with jitter to avoid thundering herd issues.
  • Rate Limit Respect: Built-in handling of 429 "Too Many Requests" responses.

🌟 Key Features

  • Intelligent Defaults: 3 retries with a 0.5s backoff factor on appropriate status codes.
  • Customizable: retry_total, retry_backoff_factor, and retry_status_codes parameters.
  • Advanced Control: Support for custom RetryPolicy objects.
  • Backward Compatible: Existing code continues to work unchanged.

🧑‍💻 Usage Examples

# Use smart defaults
client = Client(token="...")

# Customize retry attempts
client = Client(token="...", retry_total=5)

# Customize backoff timing
client = Client(token="...", retry_backoff_factor=1.0)

# Customize retry status codes
client = Client(token="...", retry_status_codes=[429, 500, 503, 408])

# Advanced custom policy
from azure.core.pipeline.policies import RetryPolicy
custom_policy = RetryPolicy(retry_total=3, retry_backoff_factor=0.8)
client = Client(token="...", retry_policy=custom_policy)

🔁 Retry Behavior

  • Exponential Backoff: Delays increase exponentially with random jitter.
  • Status Code Intelligence: Only retries on recoverable errors.
  • Rate Limit Handling: Automatically respects and handles 429 responses.
  • Network Resilience: Handles timeouts and connection errors gracefully.

📄 Files Changed

  • src/pydo/_patch.py — Added retry configuration to Client.__init__
  • README.md — Comprehensive retry documentation and usage examples
  • tests/mocked/test_retry_config.py — Full test coverage for retry scenarios

💥 Impact

  • Reliability: Client automatically handles transient failures
  • User Experience: Users no longer need to implement manual retry logic
  • Production Ready: Suitable for robust, production-grade applications
  • Performance: Intelligent backoff helps prevent overwhelming servers

🧪 Testing

  • Added comprehensive tests for both retry success and failure scenarios
  • Verified that custom retry configurations work as expected
  • Ensured that non-retryable errors do not trigger retries
  • Backward compatibility fully maintained

Feedback and suggestions are welcome!

@LifeJiggy
Copy link
Author

Hi maintainers and reviewers!

This PR adds robust, configurable retry logic to the pydo client, significantly improving reliability and user experience when dealing with network or server-side issues. The implementation is both flexible and backward compatible, with clear documentation and thorough testing.

When you have a moment, could you please review and share your feedback? I’m happy to address any questions or make further adjustments as needed.

Thank you for your time and consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant