arpakitlib 1.5.29__py3-none-any.whl → 1.5.31__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.
- arpakitlib/ar_fastapi_util.py +11 -10
- arpakitlib/ar_http_request_util.py +13 -11
- arpakitlib/ar_operation_execution_util.py +2 -5
- arpakitlib/ar_schedule_uust_api_client.py +2 -10
- arpakitlib/ar_story_log_util.py +37 -0
- {arpakitlib-1.5.29.dist-info → arpakitlib-1.5.31.dist-info}/METADATA +1 -1
- {arpakitlib-1.5.29.dist-info → arpakitlib-1.5.31.dist-info}/RECORD +10 -9
- {arpakitlib-1.5.29.dist-info → arpakitlib-1.5.31.dist-info}/LICENSE +0 -0
- {arpakitlib-1.5.29.dist-info → arpakitlib-1.5.31.dist-info}/NOTICE +0 -0
- {arpakitlib-1.5.29.dist-info → arpakitlib-1.5.31.dist-info}/WHEEL +0 -0
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -6,6 +6,7 @@ import asyncio
|
|
6
6
|
import logging
|
7
7
|
import os.path
|
8
8
|
import pathlib
|
9
|
+
from datetime import datetime
|
9
10
|
from typing import Any, Callable
|
10
11
|
|
11
12
|
import fastapi.exceptions
|
@@ -52,6 +53,12 @@ class BaseAPISO(BaseAPISchema):
|
|
52
53
|
pass
|
53
54
|
|
54
55
|
|
56
|
+
class BaseAPISimpleSO(BaseAPISO):
|
57
|
+
id: int
|
58
|
+
long_id: str
|
59
|
+
creation_dt: datetime
|
60
|
+
|
61
|
+
|
55
62
|
class APIErrorSO(BaseAPISO):
|
56
63
|
class APIErrorCodes(EasyEnumeration):
|
57
64
|
cannot_authorize = "CANNOT_AUTHORIZE"
|
@@ -243,7 +250,7 @@ def add_ar_fastapi_static_docs_and_redoc_handlers_to_fastapi_app(
|
|
243
250
|
return fastapi_app
|
244
251
|
|
245
252
|
|
246
|
-
class
|
253
|
+
class BaseAPIEvent:
|
247
254
|
def __init__(self, *args, **kwargs):
|
248
255
|
self._logger = logging.getLogger(self.__class__.__name__)
|
249
256
|
|
@@ -251,11 +258,6 @@ class BaseAPIStartupEvent:
|
|
251
258
|
self._logger.info("on_startup starts")
|
252
259
|
self._logger.info("on_startup ends")
|
253
260
|
|
254
|
-
|
255
|
-
class BaseAPIShutdownEvent:
|
256
|
-
def __init__(self, *args, **kwargs):
|
257
|
-
self._logger = logging.getLogger(self.__class__.__name__)
|
258
|
-
|
259
261
|
async def on_shutdown(self, *args, **kwargs):
|
260
262
|
self._logger.info("on_shutdown starts")
|
261
263
|
self._logger.info("on_shutdown ends")
|
@@ -265,8 +267,7 @@ def create_fastapi_app(
|
|
265
267
|
*,
|
266
268
|
title: str,
|
267
269
|
description: str | None = None,
|
268
|
-
|
269
|
-
api_shutdown_event: BaseAPIShutdownEvent | None = BaseAPIShutdownEvent(),
|
270
|
+
api_event: BaseAPIEvent | None = BaseAPIEvent(),
|
270
271
|
api_handle_exception_: Callable | None = simple_api_handle_exception
|
271
272
|
):
|
272
273
|
app = FastAPI(
|
@@ -275,8 +276,8 @@ def create_fastapi_app(
|
|
275
276
|
docs_url=None,
|
276
277
|
redoc_url=None,
|
277
278
|
openapi_url="/openapi",
|
278
|
-
on_startup=[
|
279
|
-
on_shutdown=[
|
279
|
+
on_startup=[api_event.on_startup] if api_event else [],
|
280
|
+
on_shutdown=[api_event.on_shutdown] if api_event else []
|
280
281
|
)
|
281
282
|
|
282
283
|
add_middleware_cors_to_fastapi_app(fastapi_app=app)
|
@@ -19,17 +19,18 @@ def sync_make_request(
|
|
19
19
|
*,
|
20
20
|
method: str = "GET",
|
21
21
|
url: str,
|
22
|
-
|
22
|
+
max_tries_: int = 9,
|
23
23
|
proxy_url_: str | None = None,
|
24
24
|
raise_for_status_: bool = False,
|
25
|
+
timeout_: timedelta = timedelta(seconds=15).total_seconds(),
|
25
26
|
**kwargs
|
26
27
|
) -> requests.Response:
|
27
28
|
tries_counter = 0
|
28
29
|
|
29
30
|
kwargs["method"] = method
|
30
31
|
kwargs["url"] = url
|
31
|
-
if
|
32
|
-
kwargs["timeout"] =
|
32
|
+
if timeout_ is not None:
|
33
|
+
kwargs["timeout"] = timeout_.total_seconds()
|
33
34
|
if proxy_url_:
|
34
35
|
kwargs["proxies"] = {
|
35
36
|
"http": proxy_url_,
|
@@ -47,8 +48,8 @@ def sync_make_request(
|
|
47
48
|
response.raise_for_status()
|
48
49
|
return response
|
49
50
|
except BaseException as exception:
|
50
|
-
_logger.warning(f"{tries_counter}/{
|
51
|
-
if tries_counter >=
|
51
|
+
_logger.warning(f"{tries_counter}/{max_tries_} {method} {url} {exception}")
|
52
|
+
if tries_counter >= max_tries_:
|
52
53
|
raise exception
|
53
54
|
sync_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
54
55
|
continue
|
@@ -58,18 +59,19 @@ async def async_make_request(
|
|
58
59
|
*,
|
59
60
|
method: str = "GET",
|
60
61
|
url: str,
|
61
|
-
|
62
|
+
max_tries_: int = 9,
|
62
63
|
proxy_url_: str | None = None,
|
63
64
|
raise_for_status_: bool = False,
|
65
|
+
timeout_: timedelta | None = timedelta(seconds=15),
|
64
66
|
**kwargs
|
65
67
|
) -> aiohttp.ClientResponse:
|
66
68
|
tries_counter = 0
|
67
69
|
|
68
70
|
kwargs["method"] = method
|
69
71
|
kwargs["url"] = url
|
70
|
-
if
|
71
|
-
kwargs["timeout"] = aiohttp.ClientTimeout(total=
|
72
|
-
if "allow_redirects" in kwargs:
|
72
|
+
if timeout_ is not None:
|
73
|
+
kwargs["timeout"] = aiohttp.ClientTimeout(total=timeout_.total_seconds())
|
74
|
+
if "allow_redirects" not in kwargs:
|
73
75
|
kwargs["allow_redirects"] = True
|
74
76
|
|
75
77
|
proxy_connector: ProxyConnector | None = None
|
@@ -87,8 +89,8 @@ async def async_make_request(
|
|
87
89
|
await response.read()
|
88
90
|
return response
|
89
91
|
except BaseException as exception:
|
90
|
-
_logger.warning(f"{tries_counter}/{
|
91
|
-
if tries_counter >=
|
92
|
+
_logger.warning(f"{tries_counter}/{max_tries_} {method} {url} {exception}")
|
93
|
+
if tries_counter >= max_tries_:
|
92
94
|
raise exception
|
93
95
|
await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
94
96
|
continue
|
@@ -16,7 +16,7 @@ from arpakitlib.ar_datetime_util import now_utc_dt
|
|
16
16
|
from arpakitlib.ar_dict_util import combine_dicts
|
17
17
|
from arpakitlib.ar_easy_sqlalchemy_util import EasySQLAlchemyDB
|
18
18
|
from arpakitlib.ar_enumeration import EasyEnumeration
|
19
|
-
from arpakitlib.ar_fastapi_util import BaseAPISO
|
19
|
+
from arpakitlib.ar_fastapi_util import BaseAPISO, BaseAPISimpleSO
|
20
20
|
from arpakitlib.ar_sqlalchemy_model_util import SimpleDBM
|
21
21
|
|
22
22
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -78,10 +78,7 @@ class OperationDBM(SimpleDBM):
|
|
78
78
|
return self.duration.total_seconds()
|
79
79
|
|
80
80
|
|
81
|
-
class OperationSO(
|
82
|
-
id: int
|
83
|
-
long_id: str
|
84
|
-
creation_dt: datetime
|
81
|
+
class OperationSO(BaseAPISimpleSO):
|
85
82
|
execution_start_dt: datetime | None
|
86
83
|
execution_finish_dt: datetime | None
|
87
84
|
status: str
|
@@ -10,7 +10,6 @@ import pytz
|
|
10
10
|
|
11
11
|
from arpakitlib.ar_dict_util import combine_dicts
|
12
12
|
from arpakitlib.ar_http_request_util import async_make_request
|
13
|
-
from arpakitlib.ar_logging_util import setup_normal_logging
|
14
13
|
from arpakitlib.ar_type_util import raise_for_type
|
15
14
|
|
16
15
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -76,13 +75,11 @@ class ScheduleUUSTAPIClient:
|
|
76
75
|
url: str,
|
77
76
|
params: dict | None = None
|
78
77
|
) -> dict[str, Any]:
|
79
|
-
params = combine_dicts(self.auth_params(), params)
|
80
78
|
response = await async_make_request(
|
81
79
|
url=url,
|
82
80
|
method="GET",
|
83
|
-
params=params,
|
81
|
+
params=combine_dicts(params, self.auth_params()),
|
84
82
|
proxy_url_=self.api_proxy_url,
|
85
|
-
max_tries=9
|
86
83
|
)
|
87
84
|
json_data = await response.json()
|
88
85
|
raise_for_type(json_data, dict)
|
@@ -190,12 +187,7 @@ def __example():
|
|
190
187
|
|
191
188
|
|
192
189
|
async def __async_example():
|
193
|
-
|
194
|
-
client = ScheduleUUSTAPIClient(
|
195
|
-
api_login="arpakit",
|
196
|
-
api_password_first_part="bAEb2wXJNNZ8"
|
197
|
-
)
|
198
|
-
await client.check_all()
|
190
|
+
pass
|
199
191
|
|
200
192
|
|
201
193
|
if __name__ == '__main__':
|
@@ -0,0 +1,37 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from sqlalchemy import TEXT
|
5
|
+
from sqlalchemy.dialects.postgresql import JSONB
|
6
|
+
from sqlalchemy.orm import Mapped, mapped_column
|
7
|
+
|
8
|
+
from arpakitlib.ar_enumeration import EasyEnumeration
|
9
|
+
from arpakitlib.ar_fastapi_util import BaseAPISO, BaseAPISimpleSO
|
10
|
+
from arpakitlib.ar_sqlalchemy_model_util import BaseDBM, SimpleDBM
|
11
|
+
|
12
|
+
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
13
|
+
|
14
|
+
|
15
|
+
class StoryLogDBM(SimpleDBM):
|
16
|
+
__tablename__ = "story_log"
|
17
|
+
|
18
|
+
class Levels(EasyEnumeration):
|
19
|
+
info = "info"
|
20
|
+
warning = "warning"
|
21
|
+
error = "error"
|
22
|
+
|
23
|
+
level: Mapped[str] = mapped_column(
|
24
|
+
TEXT, insert_default=Levels.info, server_default=Levels.info, index=True, nullable=False
|
25
|
+
)
|
26
|
+
title: Mapped[str | None] = mapped_column(TEXT, index=True, default=None, nullable=True)
|
27
|
+
data: Mapped[dict[str, Any]] = mapped_column(
|
28
|
+
JSONB, insert_default={}, server_default="{}", index=True, nullable=False
|
29
|
+
)
|
30
|
+
|
31
|
+
|
32
|
+
class AdminStoryLogSO(BaseAPISimpleSO):
|
33
|
+
level: str
|
34
|
+
title: str | None
|
35
|
+
data: dict[str, Any]
|
36
|
+
|
37
|
+
|
@@ -36,11 +36,11 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
36
36
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
37
37
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
38
38
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
39
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
39
|
+
arpakitlib/ar_fastapi_util.py,sha256=A5cSh1axaqN4yE2E5QPLDK58aEZgT24fIQ4pgzAMI7I,9798
|
40
40
|
arpakitlib/ar_file_storage_in_dir.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
41
41
|
arpakitlib/ar_generate_env_example.py,sha256=WseNlk_So6mTVQ2amMuigWYV4ZVmd940POvXtodoYj0,325
|
42
42
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
43
|
-
arpakitlib/ar_http_request_util.py,sha256=
|
43
|
+
arpakitlib/ar_http_request_util.py,sha256=DooIL24jW6Ouz771TMTTvzDZETBc12R1RBmbXp9vNqg,3129
|
44
44
|
arpakitlib/ar_ip_util.py,sha256=aEAa1Hvobh9DWX7cmBAPLqnXSTiKe2hRk-WJaiKMaI8,1009
|
45
45
|
arpakitlib/ar_json_db.py,sha256=CEyhIU4WuNmX5mqwBVYxUKSdpFelXvWmf_tJ1fuxMSE,7187
|
46
46
|
arpakitlib/ar_json_util.py,sha256=S8CskZ3uoYuJGCy1GhQ8Ikhn-fxXk-9JpLUbBvXADqI,833
|
@@ -51,20 +51,21 @@ arpakitlib/ar_logging_util.py,sha256=c5wX2FLqCzb4aLckLVhIJ7go52rJQ4GN9dIkJ6KMc3o
|
|
51
51
|
arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
|
52
52
|
arpakitlib/ar_need_type_util.py,sha256=qCRSWlSgx-3yU0NRHZDQ5lCOmuZKcz2Na3py9nr6hJM,1618
|
53
53
|
arpakitlib/ar_openai_util.py,sha256=d5Aj1O2yo_zYLZCLeOLvuveYYxA2jGOqhMs1oUbuVk8,1210
|
54
|
-
arpakitlib/ar_operation_execution_util.py,sha256=
|
54
|
+
arpakitlib/ar_operation_execution_util.py,sha256=PGyyvJoYAv01MWQl1TNWGamchfIrDkSovLrNMiyKqEg,11770
|
55
55
|
arpakitlib/ar_parse_command.py,sha256=qpr2OwG3Bf7DFiL9S3iWgtbvtE80RSC35E5zFJvjG1I,2714
|
56
56
|
arpakitlib/ar_postgresql_util.py,sha256=SAHEmAyMkZe516uk2gS830v_Wn2kRUZUYNcTNwmgXJk,1160
|
57
57
|
arpakitlib/ar_run_cmd.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
58
|
-
arpakitlib/ar_schedule_uust_api_client.py,sha256=
|
58
|
+
arpakitlib/ar_schedule_uust_api_client.py,sha256=1JGUy6rrjAXdWjeAqiAOQlCAEV3xuc5FUDWfXODKB-A,5770
|
59
59
|
arpakitlib/ar_sleep_util.py,sha256=9ZN4Qo4eZ_q3hjM7vNBQjFRcH-9-sqv3QLSjnxVJE90,1405
|
60
60
|
arpakitlib/ar_sqlalchemy_model_util.py,sha256=3zscvaloi9XY1NR70rJ4-jJlFUIqhmTbQ9wdvK-Yjf8,1379
|
61
61
|
arpakitlib/ar_ssh_runner.py,sha256=jlnss4V4pziBN1rBzoK_lDiWm6nMOqGXfa6NFJSKH-Y,6796
|
62
|
+
arpakitlib/ar_story_log_util.py,sha256=NKzC1nZkjofRTePHhncatO7B25hAFPvIwG45XWjI0tQ,1060
|
62
63
|
arpakitlib/ar_str_util.py,sha256=xSEzmsDvRiZVaxyqFFjcgzpphktCbXg2FHcvsd1DYpA,1885
|
63
64
|
arpakitlib/ar_type_util.py,sha256=-h-SCsVl11eVo1u4hy2Asn0IfD5TIxmX3Ndug4AvnPE,1761
|
64
65
|
arpakitlib/ar_yookassa_api_client.py,sha256=BwsTygaXf35AACVBl_09uYlSD_t-U1OOzbj58OOFT4Q,6480
|
65
66
|
arpakitlib/ar_zabbix_util.py,sha256=MTQbmS0QpNCKNOGONNQHf6j7KTZsKGlIbd5rCH0R0WI,6313
|
66
|
-
arpakitlib-1.5.
|
67
|
-
arpakitlib-1.5.
|
68
|
-
arpakitlib-1.5.
|
69
|
-
arpakitlib-1.5.
|
70
|
-
arpakitlib-1.5.
|
67
|
+
arpakitlib-1.5.31.dist-info/LICENSE,sha256=1jqWIkbnMxDfs_i0SXP5qbV6PHjBr1g8506oW7uPjfg,11347
|
68
|
+
arpakitlib-1.5.31.dist-info/METADATA,sha256=2nk5FfCHFT4sV_hZ8MKq3LlSc6NauO5Fw6gxrQPGefs,2330
|
69
|
+
arpakitlib-1.5.31.dist-info/NOTICE,sha256=wHwmiq3wExfFfgMsE5U5TOBP9_l72ocIG82KurEels0,43
|
70
|
+
arpakitlib-1.5.31.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
71
|
+
arpakitlib-1.5.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|