arkindex-client 1.0.15__tar.gz → 1.0.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/PKG-INFO +1 -1
  2. arkindex-client-1.0.16/VERSION +1 -0
  3. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/client.py +40 -1
  4. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/pagination.py +1 -1
  5. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex_client.egg-info/PKG-INFO +1 -1
  6. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex_client.egg-info/requires.txt +1 -0
  7. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/requirements.txt +1 -0
  8. arkindex-client-1.0.15/VERSION +0 -1
  9. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/MANIFEST.in +0 -0
  10. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/README.rst +0 -0
  11. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/__init__.py +0 -0
  12. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/auth.py +0 -0
  13. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/exceptions.py +0 -0
  14. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/mock.py +0 -0
  15. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex/transports.py +0 -0
  16. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex_client.egg-info/SOURCES.txt +0 -0
  17. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex_client.egg-info/dependency_links.txt +0 -0
  18. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/arkindex_client.egg-info/top_level.txt +0 -0
  19. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/setup.cfg +0 -0
  20. {arkindex-client-1.0.15 → arkindex-client-1.0.16}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-client
3
- Version: 1.0.15
3
+ Version: 1.0.16
4
4
  Summary: API client for the Arkindex project
5
5
  Home-page: https://gitlab.teklia.com/arkindex/api-client
6
6
  Author: Teklia <contact@teklia.com>
@@ -0,0 +1 @@
1
+ 1.0.16
@@ -11,6 +11,14 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
11
11
  import apistar
12
12
  import requests
13
13
  import yaml
14
+ from apistar.exceptions import ErrorResponse
15
+ from tenacity import (
16
+ before_sleep_log,
17
+ retry,
18
+ retry_if_exception,
19
+ stop_after_attempt,
20
+ wait_exponential,
21
+ )
14
22
 
15
23
  from arkindex.auth import TokenSessionAuthentication
16
24
  from arkindex.exceptions import SchemaError
@@ -27,6 +35,17 @@ SCHEMA_ENDPOINT = "/api/v1/openapi/?format=json"
27
35
  logger = logging.getLogger(__name__)
28
36
 
29
37
 
38
+ def _is_500_error(exc: Exception) -> bool:
39
+ """
40
+ Check if an Arkindex API error is a 50x
41
+ This is used to retry most API calls implemented here
42
+ """
43
+ if not isinstance(exc, ErrorResponse):
44
+ return False
45
+
46
+ return 500 <= exc.status_code < 600
47
+
48
+
30
49
  def options_from_env():
31
50
  """
32
51
  Get API client keyword arguments from environment variables.
@@ -245,7 +264,7 @@ class ArkindexClient(apistar.Client):
245
264
  self.transport.session.auth.token = resp["auth_token"]
246
265
  return resp
247
266
 
248
- def request(self, operation_id, *args, **kwargs):
267
+ def single_request(self, operation_id, *args, **kwargs):
249
268
  """
250
269
  Perform an API request.
251
270
  :param args: Arguments passed to the APIStar client.
@@ -274,3 +293,23 @@ class ArkindexClient(apistar.Client):
274
293
  )
275
294
  sleep(self.sleep_duration)
276
295
  return super().request(operation_id, *args, **kwargs)
296
+
297
+ @retry(
298
+ retry=retry_if_exception(_is_500_error),
299
+ wait=wait_exponential(multiplier=2, min=3),
300
+ reraise=True,
301
+ stop=stop_after_attempt(5),
302
+ before_sleep=before_sleep_log(logger, logging.INFO),
303
+ )
304
+ def request(self, operation_id, *args, **kwargs):
305
+ """
306
+ Proxy all Arkindex API requests with a retry mechanism in case of 50X errors.
307
+ The same API call will be retried 5 times, with an exponential sleep time
308
+ going through 3, 4, 8 and 16 seconds of wait between call.
309
+ If the 5th call still gives a 50x, the exception is re-raised and the caller should catch it.
310
+ Log messages are displayed before sleeping (when at least one exception occurred).
311
+
312
+ :param args: Arguments passed to the APIStar client.
313
+ :param kwargs: Keyword arguments passed to the APIStar client.
314
+ """
315
+ return self.single_request(operation_id, *args, **kwargs)
@@ -124,7 +124,7 @@ class ResponsePaginator(Sized, Iterator):
124
124
  )
125
125
 
126
126
  # Fetch the next page
127
- self.data = self.client.request(
127
+ self.data = self.client.single_request(
128
128
  self.operation_id,
129
129
  *self.request_args,
130
130
  **self.request_kwargs,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-client
3
- Version: 1.0.15
3
+ Version: 1.0.16
4
4
  Summary: API client for the Arkindex project
5
5
  Home-page: https://gitlab.teklia.com/arkindex/api-client
6
6
  Author: Teklia <contact@teklia.com>
@@ -1,3 +1,4 @@
1
1
  apistar==0.7.2
2
2
  requests~=2.28
3
+ tenacity==8.2.3
3
4
  typesystem==0.2.5
@@ -1,3 +1,4 @@
1
1
  apistar==0.7.2
2
2
  requests~=2.28
3
+ tenacity==8.2.3
3
4
  typesystem==0.2.5
@@ -1 +0,0 @@
1
- 1.0.15