Skip to content

SmartRetryMiddleware #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 19, 2025
Merged

SmartRetryMiddleware #451

merged 4 commits into from
Apr 19, 2025

Conversation

GefMar
Copy link
Contributor

@GefMar GefMar commented Apr 19, 2025

Problem It Solves

In many real-world scenarios, tasks may fail due to transient issues like network instability or temporary unavailability of external services. Without a retry mechanism, such failures require manual intervention. This middleware provides automatic retry logic, reducing the need for manual restarts and increasing overall system resilience.

Key Features
• ✅ Retry support with configurable maximum number of attempts (max_retries)
• ⏱️ Customizable delay between retries (delay)
• 📈 Support for exponential backoff (use_delay_exponent)
• 🎲 Optional jitter to randomize delay and reduce retry bursts (use_jitter)
• 🏷️ Label-based control at the task level:
• retry_on_error
• max_retries
• delay
• ⏳ Ability to use a custom ScheduleSource for flexible rescheduling
• ❌ Optionally replaces the task result with NoResultError until retries are exhausted (no_result_on_retry)

How It Works

When a task raises an exception:
1. The middleware checks if retries are enabled via the retry_on_error label.
2. If the retry count hasn’t reached the maximum, the task is rescheduled with a computed delay.
3. If no_result_on_retry is enabled, the task result is temporarily replaced with NoResultError, allowing for deferred handling.

rename: middleware file
@GefMar GefMar force-pushed the SmartRetryMiddleware branch from bbc74f9 to e335493 Compare April 19, 2025 16:16
@GefMar GefMar requested a review from s3rius April 19, 2025 16:33
s3rius
s3rius previously approved these changes Apr 19, 2025
s3rius
s3rius previously approved these changes Apr 19, 2025
fix: condition
@GefMar GefMar force-pushed the SmartRetryMiddleware branch from 02f642b to e6fe9e0 Compare April 19, 2025 20:43
@GefMar GefMar merged commit 27b63e0 into master Apr 19, 2025
66 checks passed
@GefMar GefMar deleted the SmartRetryMiddleware branch April 19, 2025 21:07
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.

2 participants