44
55import asyncio
66import datetime
7+ import logging
78import os
89import ssl
910import urllib .parse
10- from collections .abc import Mapping
1111from json import JSONDecodeError
1212from types import TracebackType
1313from typing import Any , cast
2222 FormData ,
2323 ServerDisconnectedError ,
2424)
25+ from backoff .types import Details
2526from botocore .client import BaseClient
2627from botocore .config import Config
2728from warrant_lite import WarrantLite
9192from pyoverkiz .obfuscate import obfuscate_sensitive_data
9293from pyoverkiz .types import JSON
9394
95+ _LOGGER = logging .getLogger (__name__ )
9496
95- async def relogin (invocation : Mapping [str , Any ]) -> None :
96- """Small helper used by retry decorators to re-authenticate the client."""
97- await invocation ["args" ][0 ].login ()
9897
98+ def _get_client_from_invocation (invocation : Details ) -> OverkizClient :
99+ """Return the `OverkizClient` instance from a backoff invocation."""
100+ return cast (OverkizClient , invocation ["args" ][0 ])
99101
100- async def refresh_listener (invocation : Mapping [str , Any ]) -> None :
101- """Helper to refresh an event listener when retrying listener-related operations."""
102- await invocation ["args" ][0 ].register_event_listener ()
102+
103+ async def relogin (invocation : Details ) -> None :
104+ """Re-authenticate using the main `OverkizClient` instance."""
105+ await _get_client_from_invocation (invocation ).login ()
106+
107+
108+ async def refresh_listener (invocation : Details ) -> None :
109+ """Refresh the listener using the main `OverkizClient` instance."""
110+ await _get_client_from_invocation (invocation ).register_event_listener ()
103111
104112
105113# Reusable backoff decorators to reduce code duplication
@@ -108,37 +116,43 @@ async def refresh_listener(invocation: Mapping[str, Any]) -> None:
108116 (NotAuthenticatedException , ServerDisconnectedError ),
109117 max_tries = 2 ,
110118 on_backoff = relogin ,
119+ logger = _LOGGER ,
111120)
112121
113122retry_on_connection_failure = backoff .on_exception (
114123 backoff .expo ,
115124 (TimeoutError , ClientConnectorError ),
116125 max_tries = 5 ,
126+ logger = _LOGGER ,
117127)
118128
119129retry_on_concurrent_requests = backoff .on_exception (
120130 backoff .expo ,
121131 TooManyConcurrentRequestsException ,
122132 max_tries = 5 ,
133+ logger = _LOGGER ,
123134)
124135
125136retry_on_too_many_executions = backoff .on_exception (
126137 backoff .expo ,
127138 TooManyExecutionsException ,
128139 max_tries = 10 ,
140+ logger = _LOGGER ,
129141)
130142
131143retry_on_listener_error = backoff .on_exception (
132144 backoff .expo ,
133145 (InvalidEventListenerIdException , NoRegisteredEventListenerException ),
134146 max_tries = 2 ,
135147 on_backoff = refresh_listener ,
148+ logger = _LOGGER ,
136149)
137150
138151retry_on_execution_queue_full = backoff .on_exception (
139152 backoff .expo ,
140153 ExecutionQueueFullException ,
141154 max_tries = 5 ,
155+ logger = _LOGGER ,
142156)
143157
144158# pylint: disable=too-many-instance-attributes, too-many-branches
0 commit comments