arpakitlib 1.6.47__py3-none-any.whl → 1.7.90__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/_arpakit_project_template/.gitignore +51 -0
- arpakitlib/_arpakit_project_template/.python-version +1 -0
- arpakitlib/_arpakit_project_template/ARPAKITLIB +1 -0
- arpakitlib/_arpakit_project_template/AUTHOR.md +4 -0
- arpakitlib/_arpakit_project_template/NOTICE +16 -0
- arpakitlib/_arpakit_project_template/README.md +6 -0
- arpakitlib/_arpakit_project_template/example.env +22 -0
- arpakitlib/_arpakit_project_template/manage/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/manage/docker_ps.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/docker_ps_a.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/docker_run_postgres_for_dev.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/docker_start_postgres_for_dev.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/docker_stop_postgres_for_dev.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/example_nginx_proxy.nginx +14 -0
- arpakitlib/_arpakit_project_template/manage/example_poetry_arpakitlib.sh +1 -0
- arpakitlib/_arpakit_project_template/manage/example_pyproject.toml +18 -0
- arpakitlib/_arpakit_project_template/manage/example_systemd.service +12 -0
- arpakitlib/_arpakit_project_template/manage/git_branch.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/git_commit.sh +3 -0
- arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_github_1.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_gitlab_1.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/git_push_arpakit_github_1.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/git_push_arpakit_gitlab_1.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/git_remote_v.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/git_set_arpakit_company_origin.sh +7 -0
- arpakitlib/_arpakit_project_template/manage/git_set_arpakit_origin.sh +7 -0
- arpakitlib/_arpakit_project_template/manage/git_status.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/hello_world.py +6 -0
- arpakitlib/_arpakit_project_template/manage/json_beutify.py +10 -0
- arpakitlib/_arpakit_project_template/manage/logging_check.py +14 -0
- arpakitlib/_arpakit_project_template/manage/note/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/manage/note/note_1.txt +0 -0
- arpakitlib/_arpakit_project_template/manage/note/note_2.txt +0 -0
- arpakitlib/_arpakit_project_template/manage/note/note_3.txt +0 -0
- arpakitlib/_arpakit_project_template/manage/note/note_4.txt +0 -0
- arpakitlib/_arpakit_project_template/manage/note/note_5.txt +0 -0
- arpakitlib/_arpakit_project_template/manage/poetry_add_plugin_export.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_check.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_clear_cache.sh +4 -0
- arpakitlib/_arpakit_project_template/manage/poetry_config_virtualenvs_in_project_true.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_generate_requirements.txt.sh +1 -0
- arpakitlib/_arpakit_project_template/manage/poetry_install.sh +5 -0
- arpakitlib/_arpakit_project_template/manage/poetry_lock.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_remove_and_add_arpakitlib.sh +7 -0
- arpakitlib/_arpakit_project_template/manage/poetry_show.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_show_arpakitlib.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_update.sh +6 -0
- arpakitlib/_arpakit_project_template/manage/poetry_update_arpakitlib.sh +5 -0
- arpakitlib/_arpakit_project_template/manage/requirements.txt +209 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_1.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_2.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_3.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_4.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_5.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_6.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_7.py +14 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_8.sh +0 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_9.sh +0 -0
- arpakitlib/_arpakit_project_template/manage/settings_check.py +10 -0
- arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py +13 -0
- arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_check_conn.py +11 -0
- arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_init.py +11 -0
- arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_reinit.py +11 -0
- arpakitlib/_arpakit_project_template/resource/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/resource/static/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/resource/static/healthcheck +1 -0
- arpakitlib/_arpakit_project_template/resource/static/helloworld +1 -0
- arpakitlib/_arpakit_project_template/src/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/additional_model/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/additional_model/additional_model.py +6 -0
- arpakitlib/_arpakit_project_template/src/api/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/asgi.py +3 -0
- arpakitlib/_arpakit_project_template/src/api/auth.py +1 -0
- arpakitlib/_arpakit_project_template/src/api/const.py +13 -0
- arpakitlib/_arpakit_project_template/src/api/create_api_app.py +117 -0
- arpakitlib/_arpakit_project_template/src/api/event.py +20 -0
- arpakitlib/_arpakit_project_template/src/api/router/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/router/main_router.py +9 -0
- arpakitlib/_arpakit_project_template/src/api/router/v1/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/router/v1/get_api_error_info.py +27 -0
- arpakitlib/_arpakit_project_template/src/api/router/v1/main_router.py +11 -0
- arpakitlib/_arpakit_project_template/src/api/schema/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/schema/v1/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/schema/v1/in_.py +0 -0
- arpakitlib/_arpakit_project_template/src/api/schema/v1/out.py +6 -0
- arpakitlib/_arpakit_project_template/src/api/start_api_for_dev.py +17 -0
- arpakitlib/_arpakit_project_template/src/api/start_api_for_dev_with_reload.py +9 -0
- arpakitlib/_arpakit_project_template/src/api/transmitted_api_data.py +9 -0
- arpakitlib/_arpakit_project_template/src/api/util.py +0 -0
- arpakitlib/_arpakit_project_template/src/business_service/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/core/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/core/const.py +48 -0
- arpakitlib/_arpakit_project_template/src/core/settings.py +86 -0
- arpakitlib/_arpakit_project_template/src/core/util.py +58 -0
- arpakitlib/_arpakit_project_template/src/db/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/db/sqlalchemy_model.py +8 -0
- arpakitlib/_arpakit_project_template/src/db/util.py +21 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/const.py +9 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/operation_executor.py +14 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py +25 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/start_operation_executor_worker_for_dev.py +18 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_worker_for_dev.py +17 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/util.py +21 -0
- arpakitlib/_arpakit_project_template/src/test_data/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/test_data/make_test_data_1.py +6 -0
- arpakitlib/_arpakit_project_template/src/test_data/make_test_data_2.py +6 -0
- arpakitlib/_arpakit_project_template/src/test_data/make_test_data_3.py +6 -0
- arpakitlib/_arpakit_project_template/src/test_data/make_test_data_4.py +6 -0
- arpakitlib/_arpakit_project_template/src/test_data/make_test_data_5.py +6 -0
- arpakitlib/_arpakit_project_template/src/util/__init__.py +0 -0
- arpakitlib/api_key_util.py +21 -0
- arpakitlib/ar_additional_model_util.py +25 -2
- arpakitlib/ar_aiogram_util.py +10 -18
- arpakitlib/ar_arpakit_lib_module_util.py +6 -1
- arpakitlib/ar_arpakit_project_template_util.py +96 -0
- arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +24 -3
- arpakitlib/ar_arpakitlib_cli_util.py +79 -0
- arpakitlib/ar_base_worker_util.py +95 -48
- arpakitlib/ar_dream_ai_api_client_util.py +26 -52
- arpakitlib/ar_enumeration_util.py +11 -0
- arpakitlib/ar_exception_util.py +18 -0
- arpakitlib/ar_fastapi_static/healthcheck +1 -0
- arpakitlib/ar_fastapi_util.py +270 -137
- arpakitlib/ar_file_util.py +22 -0
- arpakitlib/ar_func_util.py +55 -0
- arpakitlib/ar_http_request_util.py +35 -6
- arpakitlib/ar_json_util.py +13 -7
- arpakitlib/ar_logging_util.py +5 -2
- arpakitlib/ar_need_type_util.py +12 -2
- arpakitlib/{ar_openai_util.py → ar_openai_api_client_util.py} +16 -2
- arpakitlib/ar_operation_execution_util.py +250 -105
- arpakitlib/ar_parse_command.py +25 -7
- arpakitlib/ar_schedule_uust_api_client_util.py +37 -23
- arpakitlib/ar_settings_util.py +37 -11
- arpakitlib/ar_sleep_util.py +0 -13
- arpakitlib/ar_sqlalchemy_model_util.py +47 -10
- arpakitlib/ar_sqlalchemy_util.py +4 -3
- arpakitlib/{ar_ssh_util.py → ar_ssh_runner_util.py} +2 -2
- arpakitlib/ar_str_util.py +43 -2
- arpakitlib/ar_type_util.py +68 -4
- arpakitlib/ar_yookassa_api_client_util.py +26 -44
- {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/METADATA +17 -8
- arpakitlib-1.7.90.dist-info/NOTICE +16 -0
- arpakitlib-1.7.90.dist-info/RECORD +186 -0
- arpakitlib-1.7.90.dist-info/entry_points.txt +3 -0
- arpakitlib/AUTHOR.md +0 -7
- arpakitlib/NOTICE +0 -2
- arpakitlib/ar_arpakitlib_info.py +0 -13
- arpakitlib/ar_generate_env_example.py +0 -22
- arpakitlib-1.6.47.dist-info/NOTICE +0 -2
- arpakitlib-1.6.47.dist-info/RECORD +0 -70
- /arpakitlib/{LICENSE → _arpakit_project_template/LICENSE} +0 -0
- /arpakitlib/{ar_zabbix_util.py → ar_zabbix_api_client_util.py} +0 -0
- {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/LICENSE +0 -0
- {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/WHEEL +0 -0
@@ -2,91 +2,138 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
import logging
|
5
|
+
import multiprocessing
|
6
|
+
import threading
|
5
7
|
from abc import ABC
|
6
8
|
from datetime import timedelta
|
9
|
+
from typing import Any
|
7
10
|
|
11
|
+
from arpakitlib.ar_enumeration_util import Enumeration
|
12
|
+
from arpakitlib.ar_func_util import is_async_function, is_sync_function
|
8
13
|
from arpakitlib.ar_sleep_util import sync_safe_sleep, async_safe_sleep
|
9
14
|
|
10
15
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
11
16
|
|
12
17
|
|
13
18
|
class BaseWorker(ABC):
|
14
|
-
|
15
|
-
|
19
|
+
def __init__(
|
20
|
+
self,
|
21
|
+
*,
|
22
|
+
timeout_after_run=timedelta(seconds=0.1),
|
23
|
+
timeout_after_err_in_run=timedelta(seconds=1),
|
24
|
+
startup_funcs: list[Any] | None = None
|
25
|
+
):
|
26
|
+
if startup_funcs is None:
|
27
|
+
startup_funcs = []
|
28
|
+
self.startup_funcs = startup_funcs
|
16
29
|
self.worker_name = self.__class__.__name__
|
17
30
|
self._logger = logging.getLogger(self.worker_name)
|
18
|
-
self.timeout_after_run =
|
19
|
-
self.timeout_after_err_in_run =
|
31
|
+
self.timeout_after_run = timeout_after_run.total_seconds()
|
32
|
+
self.timeout_after_err_in_run = timeout_after_err_in_run.total_seconds()
|
33
|
+
|
34
|
+
def sync_run_startup_funcs(self):
|
35
|
+
for startup_func in self.startup_funcs:
|
36
|
+
if is_async_function(startup_func):
|
37
|
+
asyncio.run(startup_func())
|
38
|
+
elif is_sync_function(startup_func):
|
39
|
+
startup_func()
|
40
|
+
else:
|
41
|
+
raise TypeError("no sync and not async")
|
20
42
|
|
21
43
|
def sync_on_startup(self):
|
22
44
|
pass
|
23
45
|
|
24
46
|
def sync_run(self):
|
25
|
-
|
47
|
+
self._logger.info("hello world")
|
26
48
|
|
27
49
|
def sync_run_on_error(self, exception: BaseException, **kwargs):
|
28
|
-
|
50
|
+
pass
|
29
51
|
|
30
52
|
def sync_safe_run(self):
|
31
|
-
self._logger.info(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
53
|
+
self._logger.info("start")
|
54
|
+
try:
|
55
|
+
self.sync_on_startup()
|
56
|
+
except BaseException as exception:
|
57
|
+
self._logger.error("error in sync_on_startup", exc_info=exception)
|
58
|
+
raise exception
|
37
59
|
while True:
|
38
|
-
|
39
60
|
try:
|
40
|
-
|
41
|
-
self._logger.info("start sync_run")
|
42
61
|
self.sync_run()
|
43
|
-
self._logger.info("finish sync_run")
|
44
|
-
|
45
|
-
if self.timeout_after_run is not None:
|
46
|
-
sync_safe_sleep(self.timeout_after_run)
|
47
|
-
|
48
62
|
except BaseException as exception:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
self._logger.error("error in sync_run", exc_info=exception)
|
64
|
+
try:
|
65
|
+
self.sync_run_on_error(exception=exception)
|
66
|
+
except BaseException as exception_:
|
67
|
+
self._logger.error("error in sync_run_on_error", exc_info=exception_)
|
68
|
+
raise exception_
|
69
|
+
if self.timeout_after_run is not None:
|
70
|
+
sync_safe_sleep(self.timeout_after_run)
|
71
|
+
|
72
|
+
async def async_run_startup_funcs(self):
|
73
|
+
for startup_func in self.startup_funcs:
|
74
|
+
if is_async_function(startup_func):
|
75
|
+
await startup_func()
|
76
|
+
elif is_sync_function(startup_func):
|
77
|
+
startup_func()
|
78
|
+
else:
|
79
|
+
raise TypeError("no sync and not async")
|
56
80
|
|
57
81
|
async def async_on_startup(self):
|
58
82
|
pass
|
59
83
|
|
60
84
|
async def async_run(self):
|
61
|
-
|
85
|
+
self._logger.info("hello world")
|
62
86
|
|
63
87
|
async def async_run_on_error(self, exception: BaseException, **kwargs):
|
64
|
-
|
88
|
+
pass
|
65
89
|
|
66
90
|
async def async_safe_run(self):
|
67
|
-
self._logger.info(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
91
|
+
self._logger.info("start async_safe_run")
|
92
|
+
try:
|
93
|
+
await self.async_on_startup()
|
94
|
+
except BaseException as exception:
|
95
|
+
self._logger.error("error in async_on_startup", exc_info=exception)
|
96
|
+
raise exception
|
73
97
|
while True:
|
74
|
-
|
75
98
|
try:
|
76
|
-
|
77
99
|
await self.async_run()
|
78
|
-
|
79
|
-
if self.timeout_after_run is not None:
|
80
|
-
await async_safe_sleep(self.timeout_after_run)
|
81
|
-
|
82
100
|
except BaseException as exception:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
101
|
+
self._logger.error("error in async_run", exc_info=exception)
|
102
|
+
try:
|
103
|
+
await self.async_run_on_error(exception=exception)
|
104
|
+
except BaseException as exception_:
|
105
|
+
self._logger.error("error in async_run_on_error", exc_info=exception_)
|
106
|
+
raise exception_
|
107
|
+
if self.timeout_after_err_in_run is not None:
|
108
|
+
await async_safe_sleep(self.timeout_after_err_in_run)
|
109
|
+
|
110
|
+
|
111
|
+
class SafeRunInBackgroundModes(Enumeration):
|
112
|
+
async_task = "async_task"
|
113
|
+
thread = "thread"
|
114
|
+
process = "process"
|
115
|
+
|
116
|
+
|
117
|
+
def safe_run_worker_in_background(*, worker: BaseWorker, mode: str) -> (
|
118
|
+
asyncio.Task | threading.Thread | multiprocessing.Process
|
119
|
+
):
|
120
|
+
if mode == SafeRunInBackgroundModes.async_task:
|
121
|
+
res: asyncio.Task = asyncio.create_task(worker.async_safe_run())
|
122
|
+
elif mode == SafeRunInBackgroundModes.thread:
|
123
|
+
res: threading.Thread = threading.Thread(
|
124
|
+
target=worker.sync_safe_run,
|
125
|
+
daemon=True
|
126
|
+
)
|
127
|
+
res.start()
|
128
|
+
elif mode == SafeRunInBackgroundModes.process:
|
129
|
+
res: multiprocessing.Process = multiprocessing.Process(
|
130
|
+
target=worker.sync_safe_run,
|
131
|
+
daemon=True
|
132
|
+
)
|
133
|
+
res.start()
|
134
|
+
else:
|
135
|
+
raise ValueError(f"unknown safe_run_mode={mode}")
|
136
|
+
return res
|
90
137
|
|
91
138
|
|
92
139
|
def __example():
|
@@ -2,16 +2,14 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
import logging
|
5
|
-
from
|
5
|
+
from typing import Any
|
6
6
|
from urllib.parse import urljoin
|
7
7
|
|
8
|
-
import
|
9
|
-
from aiohttp import ClientResponseError, ClientResponse, ClientTimeout
|
8
|
+
from aiohttp import ClientResponse
|
10
9
|
from pydantic import ConfigDict, BaseModel
|
11
10
|
|
12
11
|
from arpakitlib.ar_base64_util import convert_base64_string_to_bytes
|
13
|
-
from arpakitlib.
|
14
|
-
from arpakitlib.ar_sleep_util import async_safe_sleep
|
12
|
+
from arpakitlib.ar_http_request_util import async_make_http_request
|
15
13
|
|
16
14
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
17
15
|
|
@@ -19,9 +17,6 @@ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
19
17
|
class BaseAPIModel(BaseModel):
|
20
18
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
21
19
|
|
22
|
-
def simple_json(self) -> str:
|
23
|
-
return safely_transfer_to_json_str(self.model_dump(mode="json"))
|
24
|
-
|
25
20
|
|
26
21
|
class GenerateImageFromNumberResApiModel(BaseAPIModel):
|
27
22
|
image_filename: str
|
@@ -34,12 +29,12 @@ class GenerateImageFromNumberResApiModel(BaseAPIModel):
|
|
34
29
|
return filepath
|
35
30
|
|
36
31
|
|
37
|
-
class
|
32
|
+
class DREAMAIAPIClient:
|
38
33
|
def __init__(
|
39
34
|
self,
|
40
35
|
*,
|
41
|
-
base_url: str = "https://api.
|
42
|
-
api_key: str | None =
|
36
|
+
base_url: str = "https://api.dreamai.arpakit.com/api/v1",
|
37
|
+
api_key: str | None = "1"
|
43
38
|
):
|
44
39
|
self._logger = logging.getLogger(__name__)
|
45
40
|
self.api_key = api_key
|
@@ -51,60 +46,39 @@ class DreamAIAPIClient:
|
|
51
46
|
if api_key is not None:
|
52
47
|
self.headers.update({"apikey": api_key})
|
53
48
|
|
54
|
-
async def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
self.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
await response.read()
|
70
|
-
return response
|
71
|
-
except Exception as err:
|
72
|
-
self._logger.warning(f"{tries}/{max_tries} {err} {method} {url}")
|
73
|
-
if tries >= max_tries:
|
74
|
-
raise err
|
75
|
-
await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
76
|
-
continue
|
49
|
+
async def _async_make_http_request(
|
50
|
+
self,
|
51
|
+
*,
|
52
|
+
method: str = "GET",
|
53
|
+
url: str,
|
54
|
+
params: dict[str, Any] | None = None
|
55
|
+
) -> ClientResponse:
|
56
|
+
response = await async_make_http_request(
|
57
|
+
method=method,
|
58
|
+
url=url,
|
59
|
+
params=params,
|
60
|
+
headers=self.headers,
|
61
|
+
)
|
62
|
+
response.raise_for_status()
|
63
|
+
return response
|
77
64
|
|
78
65
|
async def healthcheck(self) -> bool:
|
79
|
-
response = await self.
|
80
|
-
response.raise_for_status()
|
66
|
+
response = await self._async_make_http_request(method="GET", url=urljoin(self.base_url, "healthcheck"))
|
81
67
|
json_data = await response.json()
|
82
|
-
return json_data["data"]["healthcheck"]
|
68
|
+
return json_data["data"]["healthcheck"] == "healthcheck"
|
83
69
|
|
84
70
|
async def is_healthcheck_good(self) -> bool:
|
85
71
|
try:
|
86
72
|
return await self.healthcheck()
|
87
|
-
except
|
88
|
-
|
89
|
-
|
90
|
-
async def auth_healthcheck(self) -> bool:
|
91
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "auth_healthcheck"))
|
92
|
-
response.raise_for_status()
|
93
|
-
json_data = await response.json()
|
94
|
-
return json_data["data"]["auth_healthcheck"]
|
95
|
-
|
96
|
-
async def is_auth_healthcheck_good(self) -> bool:
|
97
|
-
try:
|
98
|
-
return await self.auth_healthcheck()
|
99
|
-
except ClientResponseError:
|
73
|
+
except Exception as exception:
|
74
|
+
self._logger.error(exception)
|
100
75
|
return False
|
101
76
|
|
102
77
|
async def generate_image_from_number(self, *, number: int) -> GenerateImageFromNumberResApiModel:
|
103
|
-
response = await self.
|
78
|
+
response = await self._async_make_http_request(
|
104
79
|
method="GET", url=urljoin(self.base_url, "generate_image_from_number"),
|
105
80
|
params={"number": number}
|
106
81
|
)
|
107
|
-
response.raise_for_status()
|
108
82
|
json_data = await response.json()
|
109
83
|
return GenerateImageFromNumberResApiModel.model_validate(json_data)
|
110
84
|
|
@@ -69,6 +69,17 @@ class Enumeration:
|
|
69
69
|
def parse_and_validate_values(cls, *values: ValuesForParseType) -> list[ValueType]:
|
70
70
|
return cls.parse_values(*values, validate=True)
|
71
71
|
|
72
|
+
@classmethod
|
73
|
+
def str_for_print(cls) -> str:
|
74
|
+
res = f"{cls.__name__} (len={len(cls.values_list())})"
|
75
|
+
for v in cls.values_list():
|
76
|
+
res += f"\n- {v}"
|
77
|
+
return res.strip()
|
78
|
+
|
79
|
+
@classmethod
|
80
|
+
def print(cls):
|
81
|
+
print(cls.str_for_print())
|
82
|
+
|
72
83
|
|
73
84
|
def __example():
|
74
85
|
pass
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import traceback
|
2
|
+
|
3
|
+
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
4
|
+
|
5
|
+
|
6
|
+
def exception_to_traceback_str(exception: BaseException) -> str:
|
7
|
+
return "".join(traceback.format_exception(type(exception), exception, exception.__traceback__))
|
8
|
+
|
9
|
+
|
10
|
+
def __example():
|
11
|
+
try:
|
12
|
+
raise Exception()
|
13
|
+
except Exception as exception:
|
14
|
+
print(exception_to_traceback_str(exception))
|
15
|
+
|
16
|
+
|
17
|
+
if __name__ == '__main__':
|
18
|
+
__example()
|
@@ -0,0 +1 @@
|
|
1
|
+
Healthcheck
|