@@ -31,6 +31,20 @@ def handle_error(resp):
3131 resp .raise_for_status ()
3232
3333
34+ def indexd_request_wrapper (func ):
35+ def retry_logic_with_timeout (* args , ** kwargs ):
36+ kwargs .update ({"timeout" : 60 })
37+ retries = 0
38+ while retries < MAX_RETRIES :
39+ try :
40+ return func (* args , ** kwargs )
41+ except requests .exceptions .ReadTimeout :
42+ retries += 1
43+ if retries == MAX_RETRIES :
44+ raise
45+
46+ return retry_logic_with_timeout
47+
3448class IndexClient (object ):
3549
3650 def __init__ (self , baseurl , version = "v0" , auth = None ):
@@ -182,16 +196,8 @@ def list_with_params(self, limit=float("inf"), start=None, page_size=100, params
182196 reformatted_params .update ({"negate_params" : json .dumps (negate_params )})
183197 yielded = 0
184198 while True :
185- tries = 0
186- while tries < MAX_RETRIES :
187- try :
188- resp = self ._get ("index" , params = reformatted_params , timeout = 60 )
189- handle_error (resp )
190- break
191- except requests .exceptions .ReadTimeout :
192- tries += 1
193- if tries == MAX_RETRIES :
194- raise
199+ resp = self ._get ("index" , params = reformatted_params , timeout = 60 )
200+ handle_error (resp )
195201 json_str = resp .json ()
196202 if not json_str ["records" ]:
197203 return
@@ -305,21 +311,25 @@ def list_versions(self, did):
305311 versions .append (Document (self , version ["did" ], version ))
306312 return versions
307313
314+ @indexd_request_wrapper
308315 def _get (self , * path , ** kwargs ):
309316 resp = requests .get (self .url_for (* path ), ** kwargs )
310317 handle_error (resp )
311318 return resp
312319
320+ @indexd_request_wrapper
313321 def _post (self , * path , ** kwargs ):
314322 resp = requests .post (self .url_for (* path ), ** kwargs )
315323 handle_error (resp )
316324 return resp
317325
326+ @indexd_request_wrapper
318327 def _put (self , * path , ** kwargs ):
319328 resp = requests .put (self .url_for (* path ), ** kwargs )
320329 handle_error (resp )
321330 return resp
322331
332+ @indexd_request_wrapper
323333 def _delete (self , * path , ** kwargs ):
324334 resp = requests .delete (self .url_for (* path ), ** kwargs )
325335 handle_error (resp )
0 commit comments