@@ -77,13 +77,11 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
77
77
self .configuration = configuration
78
78
self .pool_threads = pool_threads
79
79
80
- self .retrying = tenacity .Retrying (stop = tenacity . stop_after_attempt ( configuration . retry_count ) ,
80
+ self .retrying = tenacity .Retrying (stop = self . should_retry_stop ,
81
81
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 ))))
87
85
88
86
self .rest_client = rest .RESTClientObject (configuration , retrying = self .retrying )
89
87
self .default_headers = {}
@@ -104,8 +102,11 @@ def __del__(self):
104
102
self ._pool .join ()
105
103
self ._pool = None
106
104
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
109
110
110
111
@property
111
112
def pool (self ):
@@ -192,13 +193,30 @@ def __call_api(
192
193
url = _host + resource_path
193
194
194
195
# 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
202
220
203
221
self .last_response = response_data
204
222
0 commit comments