pybiolib 1.1.988__py3-none-any.whl → 1.1.997__py3-none-any.whl

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.
@@ -1,6 +1,8 @@
1
1
  import datetime
2
2
  from urllib.parse import urlparse, parse_qs
3
3
 
4
+ from biolib.biolib_logging import logger
5
+
4
6
  from biolib.biolib_api_client.biolib_job_api import BiolibJobApi
5
7
  from biolib.biolib_binary_format.utils import RemoteEndpoint
6
8
 
@@ -23,5 +25,6 @@ class RemoteJobStorageResultEndpoint(RemoteEndpoint):
23
25
  query_params = parse_qs(parsed_url.query)
24
26
  time_at_generation = datetime.datetime.strptime(query_params['X-Amz-Date'][0], '%Y%m%dT%H%M%SZ')
25
27
  self._expires_at = time_at_generation + datetime.timedelta(seconds=int(query_params['X-Amz-Expires'][0]))
28
+ logger.debug(f'Job "{self._job_id}" fetched presigned URL with expiry at {self._expires_at.isoformat()}')
26
29
 
27
30
  return self.presigned_url
@@ -1,10 +1,12 @@
1
1
  from abc import ABC, abstractmethod
2
-
3
2
  import io
3
+ import time
4
4
 
5
5
  import requests
6
+ from requests import Response
6
7
 
7
- from biolib.typing_utils import Iterable
8
+ from biolib.biolib_logging import logger
9
+ from biolib.typing_utils import Iterable, Optional, Dict
8
10
  from biolib.utils.multipart_uploader import get_chunk_iterator_from_bytes
9
11
 
10
12
 
@@ -49,6 +51,46 @@ class IndexableBuffer(ABC):
49
51
  return data
50
52
 
51
53
 
54
+ def _get_request_with_retries_for_timeout(
55
+ url: str,
56
+ headers: Optional[Dict[str, str]] = None,
57
+ stream: bool = False,
58
+ ) -> Response:
59
+ retries = 10
60
+ for retry_count in range(retries):
61
+ if retry_count > 0:
62
+ time.sleep(1 * retry_count)
63
+ logger.debug('Retrying HTTP GET request...')
64
+
65
+ try:
66
+ response = requests.get(
67
+ headers=headers,
68
+ stream=stream,
69
+ timeout=10,
70
+ url=url,
71
+ )
72
+ except requests.exceptions.ReadTimeout:
73
+ logger.debug('Got read timeout of HTTP GET request')
74
+ continue
75
+
76
+ if response.status_code == 502:
77
+ logger.debug('Got 502 status for HTTP GET')
78
+ continue
79
+
80
+ if response.status_code == 400:
81
+ logger.error(
82
+ f'GET request for "{url}" got response with status {response.status_code} and '
83
+ f'content: {response.content.decode()}'
84
+ )
85
+
86
+ if not response.ok:
87
+ raise Exception(f'GET request for "{url}" got response with status {response.status_code}')
88
+
89
+ return response
90
+
91
+ raise Exception(f'Failed to complete HTTP GET request for "{url}" after {retries} retries')
92
+
93
+
52
94
  class RemoteIndexableBuffer(IndexableBuffer):
53
95
 
54
96
  def __init__(self, endpoint: RemoteEndpoint):
@@ -63,9 +105,10 @@ class RemoteIndexableBuffer(IndexableBuffer):
63
105
  return bytes(0)
64
106
 
65
107
  end = start + length - 1
66
- response = requests.get(url=self._endpoint.get_remote_url(), headers={'range': f'bytes={start}-{end}'})
67
- if not response.ok:
68
- raise Exception(f'get_data got not ok response status {response.status_code}')
108
+ response = _get_request_with_retries_for_timeout(
109
+ url=self._endpoint.get_remote_url(),
110
+ headers={'range': f'bytes={start}-{end}'},
111
+ )
69
112
 
70
113
  data: bytes = response.content
71
114
  if len(data) != length:
@@ -81,11 +124,10 @@ class RemoteIndexableBuffer(IndexableBuffer):
81
124
  return []
82
125
 
83
126
  end = start + length - 1
84
- response = requests.get(
127
+ response = _get_request_with_retries_for_timeout(
85
128
  url=self._endpoint.get_remote_url(),
86
129
  headers={'range': f'bytes={start}-{end}'},
87
130
  stream=True,
88
- timeout=60,
89
131
  )
90
132
  return response.iter_content(chunk_size=chunk_size)
91
133
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pybiolib
3
- Version: 1.1.988
3
+ Version: 1.1.997
4
4
  Summary: BioLib Python Client
5
5
  Home-page: https://github.com/biolib
6
6
  License: MIT
@@ -25,14 +25,14 @@ biolib/biolib_binary_format/common_types.py,sha256=wlxstqO0Wajw8y_Rt6Gmiw4dZlf2D
25
25
  biolib/biolib_binary_format/encrypted_module_output.py,sha256=yqqfhnNymVd22cazn1Y8gDganLKiAHB2qptr4MP9BmU,6450
26
26
  biolib/biolib_binary_format/module_input.py,sha256=E-mvq26NFpYM7fqMMj8Nrpqxezy4CWRA1OS3hJK1kk0,2603
27
27
  biolib/biolib_binary_format/module_output.py,sha256=8tExFYF2kBXK3VyIRMptrRxpBN-ImxUR3PJmk6wK5jA,2640
28
- biolib/biolib_binary_format/remote_endpoints.py,sha256=k9PCHsFtMwcF1F3lWmeE88vY-1ejQn35ntRsNibmYV4,1146
28
+ biolib/biolib_binary_format/remote_endpoints.py,sha256=LgWd_cewZK4ncPR8303GM_PmIEZZJ5RQatJ_NSXUgbU,1306
29
29
  biolib/biolib_binary_format/rsa_encrypted_aes_package.py,sha256=p2IAv1_FH67qQV3rj1fXKDQNSFxMuLaHEbuJ6WxRLdc,2269
30
30
  biolib/biolib_binary_format/saved_job.py,sha256=nFHVFRNTNcAFGODLSiBntCtMk55QKwreUq6qLX80dI4,1125
31
31
  biolib/biolib_binary_format/stdout_and_stderr.py,sha256=WfUUJFFCBrtfXjuWIaRPiWCpuBLxfko68oxoTKhrwx8,1023
32
32
  biolib/biolib_binary_format/system_exception.py,sha256=T3iL4_cSHAHim3RSDPS8Xyb1mfteaJBZonSXuRltc28,853
33
33
  biolib/biolib_binary_format/system_status_update.py,sha256=aOELuQ0k-GtpaZTUxYd0GFomP_OInmrK585y6fuQuKE,1191
34
34
  biolib/biolib_binary_format/unencrypted_module_output.py,sha256=Op9NqlSwwoRKbf7ecHgBChrXdJHEAzKjREojv6d5I3g,8514
35
- biolib/biolib_binary_format/utils.py,sha256=n96tiAQhDi_rZNA4uAvnbo2m8NyriJNhwpQAMLOy25E,4101
35
+ biolib/biolib_binary_format/utils.py,sha256=wAC21bfqvz27Ug41kKaASouYChXNYh49DEI8_VKhWfk,5402
36
36
  biolib/biolib_docker_client/__init__.py,sha256=aBfA6mtWSI5dBEfNNMD6bIZzCPloW4ghKm0wqQiljdo,1481
37
37
  biolib/biolib_errors.py,sha256=5m4lK2l39DafpoXBImEBD4EPH3ayXBX0JgtPzmGClow,689
38
38
  biolib/biolib_logging.py,sha256=J3E5H_LL5k6ZUim2C8gqN7E6lCBZMTpO4tnMpOPwG9U,2854
@@ -107,8 +107,8 @@ biolib/validators/validate_argument.py,sha256=B-tqgMgXuTvJLhaMWcBTUKw18L5brJtIdf
107
107
  biolib/validators/validate_module.py,sha256=aHe0YAWFSrMbZNw-h64oweqruDS-k7KOUzK1ECpG8Wg,13298
108
108
  biolib/validators/validate_zip_file.py,sha256=2j8kJ1WF2u5OyMkfEDCoU_BvOtr8gLPWTtsmUG0zQ5g,1655
109
109
  biolib/validators/validator_utils.py,sha256=2QCJWdKiLTUHsvjDidrXKBjH95kKsEmFwd17muTGL0M,2135
110
- pybiolib-1.1.988.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
111
- pybiolib-1.1.988.dist-info/METADATA,sha256=qTgiAy3kZ2RNdm234TGjUK1_AFci5-j996O0XpERXcM,1611
112
- pybiolib-1.1.988.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
113
- pybiolib-1.1.988.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
114
- pybiolib-1.1.988.dist-info/RECORD,,
110
+ pybiolib-1.1.997.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
111
+ pybiolib-1.1.997.dist-info/METADATA,sha256=YrBf4WneR9rWEcM86GPgz_JEByZyelZHBAiL_EtkMN8,1611
112
+ pybiolib-1.1.997.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
113
+ pybiolib-1.1.997.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
114
+ pybiolib-1.1.997.dist-info/RECORD,,