Skip to content

Commit eee6d1b

Browse files
Fizzadartulir
andauthored
More proxy_with_retry helper arguments (#136)
* Add `min_wait_seconds` argument to `proxy_with_retry` helper * Add `retryable_exceptions` argument to `proxy_with_retry` helper This allows non-aiohttp calls to use the helper to retry proxy related requests. * Stricter type for `retryable_exceptions` Co-authored-by: Tulir Asokan <[email protected]> --------- Co-authored-by: Tulir Asokan <[email protected]>
1 parent 090f333 commit eee6d1b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mautrix/util/proxy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,19 @@ async def proxy_with_retry(
9090
proxy_handler: ProxyHandler,
9191
on_proxy_change: Callable[[], Awaitable[None]],
9292
max_retries: int = 10,
93+
min_wait_seconds: int = 60,
94+
retryable_exceptions: tuple[Exception] = RETRYABLE_PROXY_EXCEPTIONS,
9395
) -> T:
9496
errors = 0
9597

9698
while True:
9799
try:
98100
return await func()
99-
except RETRYABLE_PROXY_EXCEPTIONS as e:
101+
except retryable_exceptions as e:
100102
errors += 1
101103
if errors > max_retries:
102104
raise
103-
wait = min(errors * 10, 60)
105+
wait = min(errors * 10, min_wait_seconds)
104106
logger.warning(
105107
"%s while trying to %s, retrying in %d seconds",
106108
e.__class__.__name__,

0 commit comments

Comments
 (0)