Skip to content

Commit 896f34b

Browse files
authored
Improve backoff retry configuration (#1993)
## Summary - Add `__all__` and re-exports to package `__init__.py` for cleaner public API - Add `max_time` and `jitter` to all backoff retry decorators for more resilient retry behavior ## Test plan - [ ] Existing tests pass - [ ] Public API exports are importable from `pyoverkiz` - [ ] Retry behavior works with new max_time/jitter settings
1 parent 389569c commit 896f34b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pyoverkiz/client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ async def refresh_listener(invocation: Details) -> None:
7676
await _get_client_from_invocation(invocation).register_event_listener()
7777

7878

79-
# Reusable backoff decorators to reduce code duplication
79+
# Reusable backoff decorators with max_tries and max_time to cap total retry duration.
8080
retry_on_auth_error = backoff.on_exception(
8181
backoff.expo,
8282
(NotAuthenticatedError, ServerDisconnectedError),
8383
max_tries=2,
84+
max_time=60, # safety net for hung requests
85+
jitter=backoff.full_jitter,
8486
on_backoff=relogin,
8587
logger=_LOGGER,
8688
)
@@ -89,27 +91,35 @@ async def refresh_listener(invocation: Details) -> None:
8991
backoff.expo,
9092
(TimeoutError, ClientConnectorError),
9193
max_tries=5,
94+
max_time=120,
95+
jitter=backoff.full_jitter,
9296
logger=_LOGGER,
9397
)
9498

9599
retry_on_concurrent_requests = backoff.on_exception(
96100
backoff.expo,
97101
TooManyConcurrentRequestsError,
98102
max_tries=5,
103+
max_time=120,
104+
jitter=backoff.full_jitter,
99105
logger=_LOGGER,
100106
)
101107

102108
retry_on_too_many_executions = backoff.on_exception(
103109
backoff.expo,
104110
TooManyExecutionsError,
105-
max_tries=10,
111+
max_tries=5,
112+
max_time=300,
113+
jitter=backoff.full_jitter,
106114
logger=_LOGGER,
107115
)
108116

109117
retry_on_listener_error = backoff.on_exception(
110118
backoff.expo,
111119
(InvalidEventListenerIdError, NoRegisteredEventListenerError),
112120
max_tries=2,
121+
max_time=30,
122+
jitter=backoff.full_jitter,
113123
on_backoff=refresh_listener,
114124
logger=_LOGGER,
115125
)
@@ -118,6 +128,8 @@ async def refresh_listener(invocation: Details) -> None:
118128
backoff.expo,
119129
ExecutionQueueFullError,
120130
max_tries=5,
131+
max_time=120,
132+
jitter=backoff.full_jitter,
121133
logger=_LOGGER,
122134
)
123135

0 commit comments

Comments
 (0)