Skip to content

Commit f0c9fbe

Browse files
Reformat retries doc
1 parent 5953b40 commit f0c9fbe

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

designs/exceptions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ If an exception with `ErrorRetryInfo` is received while attempting to send a
6363
serialized request to the server, the contained information will be used to
6464
inform the next retry.
6565

66-
See the retry design for more details on how this information is used.
66+
See the
67+
[retry design](https://github.com/smithy-lang/smithy-python/blob/develop/designs/retries.md)
68+
for more details on how this information is used.
6769

6870
### Service Errors
6971

designs/retries.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,6 @@ class RetryStrategy(Protocol):
6363
...
6464
```
6565

66-
A request using a `RetryStrategy` would look something like the following
67-
example:
68-
69-
```python
70-
try:
71-
retry_token = retry_strategy.acquire_initial_retry_token()
72-
except RetryError:
73-
transpoort_response = transport_client.send(serialized_request)
74-
return self._deserialize(transport_response)
75-
76-
while True:
77-
await asyncio.sleep(retry_token.retry_delay)
78-
try:
79-
transpoort_response = transport_client.send(serialized_request)
80-
response = self._deserialize(transport_response)
81-
except Exception as e:
82-
response = e
83-
84-
if isinstance(response, Exception):
85-
try:
86-
retry_token = retry_strategy.refresh_retry_token_for_retry(
87-
token_to_renew=retry_token,
88-
error=e
89-
)
90-
continue
91-
except RetryError retry_error:
92-
raise retry_error from e
93-
94-
retry_strategy.record_success(token=retry_token)
95-
return response
96-
```
97-
9866
### Error Classification
9967

10068
Different types of exceptions may require different amounts of delay or may not
@@ -168,3 +136,37 @@ example, a `BackoffStrategy` could use a token bucket to limit retries
168136
client-wide so that the client can limit the amount of load it is placing on the
169137
server. Decoupling this logic from the straightforward math of delay computation
170138
allows both components to be evolved separately.
139+
140+
## Example Usage
141+
142+
A request using a `RetryStrategy` would look something like the following
143+
example:
144+
145+
```python
146+
try:
147+
retry_token = retry_strategy.acquire_initial_retry_token()
148+
except RetryError:
149+
transport_response = transport_client.send(serialized_request)
150+
return self._deserialize(transport_response)
151+
152+
while True:
153+
await asyncio.sleep(retry_token.retry_delay)
154+
try:
155+
transport_response = transport_client.send(serialized_request)
156+
response = self._deserialize(transport_response)
157+
except Exception as e:
158+
response = e
159+
160+
if isinstance(response, Exception):
161+
try:
162+
retry_token = retry_strategy.refresh_retry_token_for_retry(
163+
token_to_renew=retry_token,
164+
error=e
165+
)
166+
continue
167+
except RetryError as retry_error:
168+
raise retry_error from e
169+
170+
retry_strategy.record_success(token=retry_token)
171+
return response
172+
```

0 commit comments

Comments
 (0)