19
19
def retry_connection_error (
20
20
attempts : int = DEFAULT_ATTEMPTS ,
21
21
exception : type [Exception ] = aiohttp .ClientError ,
22
- backoff : float | None = None ,
23
22
) -> Callable [[Callable [P , Awaitable [T ]]], Callable [P , Awaitable [T ]]]:
24
23
"""Define a wrapper to retry on connection error."""
25
- if backoff is None :
26
- backoff = BACKOFF_TIME
27
24
28
25
def _decorator_retry_connection_error (
29
26
func : Callable [P , Awaitable [T ]],
@@ -38,17 +35,8 @@ def _decorator_retry_connection_error(
38
35
async def _async_wrap_connection_error_retry ( # type: ignore[return]
39
36
* args : P .args , ** kwargs : P .kwargs
40
37
) -> T :
41
- logger .debug (
42
- "retry_connection_error wrapper called for %s with exception=%s, attempts=%s" ,
43
- func .__name__ ,
44
- exception ,
45
- attempts ,
46
- )
47
38
for attempt in range (attempts ):
48
39
try :
49
- logger .debug (
50
- "Attempt %s/%s for %s" , attempt + 1 , attempts , func .__name__
51
- )
52
40
return await func (* args , ** kwargs )
53
41
except exception as ex :
54
42
#
@@ -61,25 +49,16 @@ async def _async_wrap_connection_error_retry( # type: ignore[return]
61
49
# to close the connection at any time, we treat this as a normal and try again
62
50
# once since we do not want to declare the camera as not supporting PullPoint
63
51
# if it just happened to close the connection at the wrong time.
64
- logger .debug (
65
- "Caught exception %s (type: %s) on attempt %s/%s" ,
66
- ex ,
67
- type (ex ).__name__ ,
68
- attempt + 1 ,
69
- attempts ,
70
- exc_info = True ,
71
- )
72
52
if attempt == attempts - 1 :
73
- logger .debug ("Final attempt failed, re-raising exception" )
74
53
raise
75
54
logger .debug (
76
55
"Error: %s while calling %s, backing off: %s, retrying..." ,
77
56
ex ,
78
57
func ,
79
- backoff ,
58
+ BACKOFF_TIME ,
80
59
exc_info = True ,
81
60
)
82
- await asyncio .sleep (backoff )
61
+ await asyncio .sleep (BACKOFF_TIME )
83
62
84
63
return _async_wrap_connection_error_retry
85
64
0 commit comments