@@ -77,13 +77,11 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
7777 self .configuration = configuration
7878 self .pool_threads = pool_threads
7979
80- self .retrying = tenacity .Retrying (stop = tenacity . stop_after_attempt ( configuration . retry_count ) ,
80+ self .retrying = tenacity .Retrying (stop = self . should_retry_stop ,
8181 wait = tenacity .wait_random_exponential (multiplier = configuration .back_off ,
82- max = configuration .retry_max_delay ,
83- min = configuration .retry_delay ),
84- retry = (tenacity .retry_if_result (self .is_retry_enabled ) and
85- ((tenacity .retry_if_exception_type (RetryableException )) |
86- (tenacity .retry_if_exception_type (HTTPError )))))
82+ max = configuration .retry_delay ),
83+ retry = (tenacity .retry_if_exception_type (RetryableException ) |
84+ (tenacity .retry_if_exception_type (HTTPError ))))
8785
8886 self .rest_client = rest .RESTClientObject (configuration , retrying = self .retrying )
8987 self .default_headers = {}
@@ -104,8 +102,11 @@ def __del__(self):
104102 self ._pool .join ()
105103 self ._pool = None
106104
107- def is_retry_enabled (self ):
108- return self .configuration .retry_enabled
105+ def should_retry_stop (self , retry_state ):
106+ if self .configuration .retry_enabled and retry_state .attempt_number <= self .configuration .retry_count and retry_state .seconds_since_start <= self .configuration .retry_max_delay :
107+ return False
108+
109+ return True
109110
110111 @property
111112 def pool (self ):
@@ -192,13 +193,30 @@ def __call_api(
192193 url = _host + resource_path
193194
194195 # perform request and return response
195- response_data = self .retrying .call (fn = self .request , method = method , url = url ,
196- query_params = query_params ,
197- headers = header_params ,
198- post_params = post_params ,
199- body = body ,
200- _preload_content = _preload_content ,
201- _request_timeout = _request_timeout )
196+ try :
197+ response_data = self .retrying .call (fn = self .request , method = method , url = url ,
198+ query_params = query_params ,
199+ headers = header_params ,
200+ post_params = post_params ,
201+ body = body ,
202+ _preload_content = _preload_content ,
203+ _request_timeout = _request_timeout )
204+ except Exception as exception :
205+ self ._sdk_request_details = {
206+ "query_params" : query_params ,
207+ "headers" : header_params ,
208+ "post_params" : post_params ,
209+ "body" : body ,
210+ "_preload_content" : _preload_content ,
211+ "_request_timeout" : _request_timeout
212+ }
213+ self .sdk_metric_publisher .build_metric (transaction_id = config .metrics_transaction_id ,
214+ duration = datetime .datetime .now () - self ._request_start_time ,
215+ resource_path = url , error_type = type (exception ),
216+ error_message = str (exception ),
217+ sdk_request_details = self ._sdk_request_details ,
218+ sdk_result_details = "An Exception Was Thrown!" )
219+ raise exception
202220
203221 self .last_response = response_data
204222
0 commit comments