Retries
RetryPolicy
¶
Bases: RetryBase
Policy for retrying requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response_rules |
list[ResponseRule]
|
Rules for retrying requests based on their responses. |
None
|
exception_rules |
list[ExceptionRule]
|
Rules for retrying requests after an exception. |
None
|
max_retries |
int
|
Maximum total number of retries. By default 3. |
3
|
timeout |
float
|
Maximum time to retry. By default 60 seconds.
Timeout is best effort and may exceed the specified time
by up to |
60
|
backoff_base |
float
|
Base time to sleep between retries. By default 0.5 seconds. |
0.5
|
backoff_factor |
float
|
Factor to increase sleep time between retries. By default 2. |
2
|
backoff_max |
float
|
Maximum time to sleep between retries. By default 10 seconds. |
10
|
backoff_jitter |
bool
|
If True, adds jitter to sleep time. By default True. |
True
|
Source code in src/aiosalesforce/retries/policy.py
create_context()
¶
Create a new retry context.
Retry context is used to handle retries for a single request.
Source code in src/aiosalesforce/retries/policy.py
ExceptionRule
¶
Bases: Generic[E]
Rule for deciding if a request should be retried after an exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc_type |
type[Exception]
|
Type of exception to retry. |
required |
func |
Callable[[Exception], Awaitable[bool] | bool] | None
|
Function or coroutine to determine if the request should be retried. By default the provided exception is always retried. |
None
|
max_retries |
int
|
Maximum number of retries. By default 3. |
3
|
Source code in src/aiosalesforce/retries/rules.py
should_retry(exc)
async
¶
Determine if the request should be retried.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc |
Exception
|
Exception from the request. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the request should be retried, False otherwise. |
Source code in src/aiosalesforce/retries/rules.py
ResponseRule
¶
Rule for deciding if a request should be retried based its response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[[Response], Awaitable[bool] | bool]
|
Function or coroutine to determine if the request should be retried. |
required |
max_retries |
int
|
Maximum number of retries. By default 3. |
3
|
Source code in src/aiosalesforce/retries/rules.py
should_retry(response)
async
¶
Determine if the request should be retried.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Response
|
Response from the request. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the request should be retried, False otherwise. |
Source code in src/aiosalesforce/retries/rules.py
RetryContext
¶
Bases: RetryBase
Context for handling retries for a single request.
Source code in src/aiosalesforce/retries/policy.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
send_request_with_retries(httpx_client, event_bus, semaphore, request)
async
¶
Send a request and retry it if necessary in accordance with the retry policy.
Does not guarantee that the returned response is OK (status code < 300), only that the request was retried according to the policy.
Emits the following events:
- RetryEvent if the request is retried
- RestApiCallConsumptionEvent for each request that did not raise an exception
Parameters:
Name | Type | Description | Default |
---|---|---|---|
httpx_client |
AsyncClient
|
HTTP client to send the request. |
required |
event_bus |
EventBus
|
Event bus to publish events. |
required |
semaphore |
Semaphore
|
Semaphore to limit the number of simultaneous requests. |
required |
request |
Request
|
Request to send. |
required |
Returns:
Type | Description |
---|---|
Response
|
Response from the request. Not guaranteed to be OK (status code < 300). |
Source code in src/aiosalesforce/retries/policy.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
should_retry(value)
async
¶
Determine if the request should be retried.
If the request should be retried, the total retry count and the retry count for the rule responsible for the retry are incremented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Response | Exception
|
Response or Exception from the request. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the request should be retried, False otherwise. |
Source code in src/aiosalesforce/retries/policy.py
sleep()
async
¶
Sleep between retries based on the backoff policy.