libentry 1.16__py3-none-any.whl → 1.18__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.
- libentry/api.py +33 -12
- libentry/service/flask.py +21 -1
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/METADATA +1 -1
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/RECORD +8 -8
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/LICENSE +0 -0
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/WHEEL +0 -0
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/top_level.txt +0 -0
- {libentry-1.16.dist-info → libentry-1.18.dist-info}/zip-safe +0 -0
libentry/api.py
CHANGED
@@ -166,6 +166,9 @@ class ServiceError(RuntimeError):
|
|
166
166
|
return "".join(lines)
|
167
167
|
|
168
168
|
|
169
|
+
ErrorCallback = Callable[[Exception], None]
|
170
|
+
|
171
|
+
|
169
172
|
class APIClient:
|
170
173
|
|
171
174
|
def __init__(
|
@@ -195,29 +198,41 @@ class APIClient:
|
|
195
198
|
self,
|
196
199
|
method: str,
|
197
200
|
url: str,
|
198
|
-
num_trials: int
|
199
|
-
|
200
|
-
|
201
|
+
num_trials: int,
|
202
|
+
timeout: float,
|
203
|
+
interval: float,
|
204
|
+
retry_factor: float,
|
205
|
+
on_error: Optional[ErrorCallback] = None,
|
201
206
|
**kwargs
|
202
207
|
):
|
203
208
|
err = None
|
204
|
-
for
|
209
|
+
for i in range(num_trials):
|
205
210
|
try:
|
206
|
-
return requests.request(
|
211
|
+
return requests.request(
|
212
|
+
method=method,
|
213
|
+
url=url,
|
214
|
+
timeout=timeout * (1 + i * retry_factor),
|
215
|
+
**kwargs
|
216
|
+
)
|
207
217
|
except requests.Timeout as e:
|
208
218
|
err = e
|
219
|
+
if callable(on_error):
|
220
|
+
on_error(e)
|
209
221
|
except requests.ConnectionError as e:
|
210
222
|
err = e
|
211
|
-
|
212
|
-
|
223
|
+
if callable(on_error):
|
224
|
+
on_error(e)
|
225
|
+
sleep(interval)
|
213
226
|
raise err
|
214
227
|
|
215
228
|
def get(
|
216
229
|
self,
|
217
230
|
path: Optional[str] = None, *,
|
218
231
|
num_trials: int = 5,
|
219
|
-
|
220
|
-
|
232
|
+
timeout: float = 15,
|
233
|
+
interval: float = 1,
|
234
|
+
retry_factor: float = 0.5,
|
235
|
+
on_error: Optional[ErrorCallback] = None
|
221
236
|
):
|
222
237
|
full_url = urljoin(self.base_url, path)
|
223
238
|
response = self._request(
|
@@ -226,8 +241,10 @@ class APIClient:
|
|
226
241
|
headers=self.headers,
|
227
242
|
verify=self.verify,
|
228
243
|
num_trials=num_trials,
|
244
|
+
timeout=timeout,
|
245
|
+
interval=interval,
|
229
246
|
retry_factor=retry_factor,
|
230
|
-
|
247
|
+
on_error=on_error
|
231
248
|
)
|
232
249
|
|
233
250
|
if response.status_code != 200:
|
@@ -247,8 +264,10 @@ class APIClient:
|
|
247
264
|
stream: bool = False,
|
248
265
|
exhaust_stream: bool = False,
|
249
266
|
num_trials: int = 5,
|
250
|
-
retry_factor: float = 2,
|
251
267
|
timeout: float = 15,
|
268
|
+
interval: float = 1,
|
269
|
+
retry_factor: float = 0.5,
|
270
|
+
on_error: Optional[ErrorCallback] = None,
|
252
271
|
chunk_delimiter: str = "\n\n",
|
253
272
|
chunk_prefix: str = None,
|
254
273
|
chunk_suffix: str = None,
|
@@ -267,8 +286,10 @@ class APIClient:
|
|
267
286
|
verify=self.verify,
|
268
287
|
stream=stream,
|
269
288
|
num_trials=num_trials,
|
289
|
+
timeout=timeout,
|
290
|
+
interval=interval,
|
270
291
|
retry_factor=retry_factor,
|
271
|
-
|
292
|
+
on_error=on_error
|
272
293
|
)
|
273
294
|
if response.status_code != 200:
|
274
295
|
text = response.text
|
libentry/service/flask.py
CHANGED
@@ -13,7 +13,6 @@ from types import GeneratorType
|
|
13
13
|
from typing import Any, Callable, Iterable, Optional, Type, Union
|
14
14
|
|
15
15
|
from flask import Flask, request
|
16
|
-
from gunicorn.app.base import BaseApplication
|
17
16
|
from pydantic import BaseModel, Field, create_model
|
18
17
|
|
19
18
|
from libentry import api, json
|
@@ -21,6 +20,26 @@ from libentry.api import APIInfo, list_api_info
|
|
21
20
|
from libentry.logging import logger
|
22
21
|
from libentry.schema import query_api
|
23
22
|
|
23
|
+
try:
|
24
|
+
from gunicorn.app.base import BaseApplication
|
25
|
+
except ImportError:
|
26
|
+
class BaseApplication:
|
27
|
+
|
28
|
+
def load(self) -> Flask:
|
29
|
+
pass
|
30
|
+
|
31
|
+
def run(self):
|
32
|
+
flask_server = self.load()
|
33
|
+
assert hasattr(self, "options")
|
34
|
+
bind = getattr(self, "options")["bind"]
|
35
|
+
pos = bind.rfind(":")
|
36
|
+
host = bind[:pos]
|
37
|
+
port = int(bind[pos + 1:])
|
38
|
+
logger.warn("Your system doesn't support gunicorn.")
|
39
|
+
logger.warn("Use Flask directly.")
|
40
|
+
logger.warn("Options like \"num_threads\", \"num_workers\" are ignored.")
|
41
|
+
return flask_server.run(host=host, port=port)
|
42
|
+
|
24
43
|
|
25
44
|
class JSONDumper:
|
26
45
|
|
@@ -373,3 +392,4 @@ def run_service(
|
|
373
392
|
for name, value in options.items():
|
374
393
|
logger.info(f"Option {name}: {value}")
|
375
394
|
GunicornApplication(service_type, service_config, options).run()
|
395
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
libentry/__init__.py,sha256=rDBip9M1Xb1N4wMKE1ni_DldrQbkRjp8DxPkTp3K2qo,170
|
2
|
-
libentry/api.py,sha256=
|
2
|
+
libentry/api.py,sha256=LqTa8T8Oh8z5BybzrgtdC0HhMXWL2-DZPdOdBHb6Vl0,10753
|
3
3
|
libentry/argparse.py,sha256=NxzXV-jBN51ReZsNs5aeyOfzwYQ5A5nJ95rWoa-FYCs,10415
|
4
4
|
libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
|
5
5
|
libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
|
@@ -10,14 +10,14 @@ libentry/schema.py,sha256=BO7EE7i43Cb4xn_OLsBM-HDwWOT6V5fPs91Am3QqnNQ,8178
|
|
10
10
|
libentry/server.py,sha256=gYPoZXd0umlDYZf-6ZV0_vJadg3YQvnLDc6JFDJh9jc,1503
|
11
11
|
libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
12
12
|
libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
|
13
|
-
libentry/service/flask.py,sha256=
|
13
|
+
libentry/service/flask.py,sha256=Alpsix01ROqI28k-dabD8wJlWAWs-ObNc1nJ-LxOXn4,13349
|
14
14
|
libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
|
15
15
|
libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
|
16
16
|
libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
|
17
17
|
libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
|
18
|
-
libentry-1.
|
19
|
-
libentry-1.
|
20
|
-
libentry-1.
|
21
|
-
libentry-1.
|
22
|
-
libentry-1.
|
23
|
-
libentry-1.
|
18
|
+
libentry-1.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
19
|
+
libentry-1.18.dist-info/METADATA,sha256=3LKED9qfL_-_CvMdtfNW2YnoK1LBDdnQxN7Bf2_ZsKE,791
|
20
|
+
libentry-1.18.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
21
|
+
libentry-1.18.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
22
|
+
libentry-1.18.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
23
|
+
libentry-1.18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|