You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/available-components/middlewares.md
+51Lines changed: 51 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,57 @@ async def test():
34
34
35
35
`retry_on_error` enables retries for a task. `max_retries` is the maximum number of times,.
36
36
37
+
## Smart Retry Middleware
38
+
39
+
The `SmartRetryMiddleware` automatically retries tasks with flexible delay settings and retry strategies when errors occur. This is particularly useful when tasks fail due to temporary issues, such as network errors or temporary unavailability of external services.
40
+
41
+
### Key Features:
42
+
43
+
***Retry Limits**: Set the maximum number of retry attempts (`max_retries`).
44
+
***Delay Before Retry**: Define a fixed delay or use additional strategies.
45
+
***Jitter**: Adds random delay variations to distribute retries evenly and prevent simultaneous task execution.
46
+
***Exponential Backoff**: Increases the delay for each subsequent retry, useful for gradually recovering system performance.
47
+
***Custom Schedule Source (`schedule_source`)**: Enables using a custom schedule source to manage delayed task execution.
48
+
49
+
### Middleware Integration
50
+
51
+
To use `SmartRetryMiddleware`, add it to the list of middlewares in your broker:
52
+
53
+
```python
54
+
from taskiq import ZeroMQBroker
55
+
from taskiq.middlewares import SmartRetryMiddleware
56
+
57
+
broker = ZeroMQBroker().with_middlewares(
58
+
SmartRetryMiddleware(
59
+
default_retry_count=5,
60
+
default_delay=10,
61
+
use_jitter=True,
62
+
use_delay_exponent=True,
63
+
max_delay_exponent=120
64
+
),
65
+
)
66
+
```
67
+
68
+
### Using Middleware with Tasks
69
+
70
+
To enable retries for a specific task, specify the following parameters:
*`retry_on_error`: Enables the retry mechanism for the specific task.
79
+
*`max_retries`: Maximum number of retries (overrides middleware default).
80
+
*`delay`: Initial delay before retrying the task, in seconds.
81
+
82
+
### Usage Recommendations
83
+
84
+
Use jitter and exponential backoff to avoid repetitive load peaks, especially in high-load systems. Choose appropriate `max_delay_exponent` values to prevent excessively long intervals between retries if your task execution is time-sensitive.
85
+
86
+
87
+
37
88
### Prometheus middleware
38
89
39
90
You can enable prometheus metrics for workers by adding PrometheusMiddleware.
0 commit comments