arpakitlib 1.8.151__py3-none-any.whl → 1.8.152__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_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py +1 -0
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/execute_func_with_story_log.py +81 -0
- {arpakitlib-1.8.151.dist-info → arpakitlib-1.8.152.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.151.dist-info → arpakitlib-1.8.152.dist-info}/RECORD +7 -6
- {arpakitlib-1.8.151.dist-info → arpakitlib-1.8.152.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.151.dist-info → arpakitlib-1.8.152.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.151.dist-info → arpakitlib-1.8.152.dist-info}/entry_points.txt +0 -0
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py
CHANGED
@@ -25,6 +25,7 @@ class StoryLogDBM(SimpleDBM):
|
|
25
25
|
error_in_execute_operation = "error_in_execute_operation"
|
26
26
|
error_in_api = "error_in_api"
|
27
27
|
error_in_tg_bot = "error_in_tg_bot"
|
28
|
+
error_in_sync_execute_with_story_log = "error_in_sync_execute_with_story_log"
|
28
29
|
|
29
30
|
level: Mapped[str] = mapped_column(
|
30
31
|
sqlalchemy.TEXT,
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/execute_func_with_story_log.py
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
import logging
|
2
|
+
from typing import Callable, Any
|
3
|
+
|
4
|
+
from arpakitlib.ar_exception_util import exception_to_traceback_str
|
5
|
+
from sqlalchemy.orm import Session
|
6
|
+
|
7
|
+
from project.core.util import setup_logging
|
8
|
+
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
9
|
+
from project.sqlalchemy_db_.sqlalchemy_model import StoryLogDBM
|
10
|
+
|
11
|
+
_logger = logging.getLogger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
def sync_execute_with_story_log(
|
15
|
+
func: Callable,
|
16
|
+
*,
|
17
|
+
func_args: tuple | None = None,
|
18
|
+
func_kwargs: dict | None = None,
|
19
|
+
session_: Session | None = None,
|
20
|
+
story_log_level: str = StoryLogDBM.Levels.error,
|
21
|
+
story_log_type: str = StoryLogDBM.Types.error_in_sync_execute_with_story_log,
|
22
|
+
story_log_title: str | None = None,
|
23
|
+
story_log_extra_data: dict | None = None,
|
24
|
+
) -> Any:
|
25
|
+
if func_args is None:
|
26
|
+
func_args = tuple()
|
27
|
+
if func_kwargs is None:
|
28
|
+
func_kwargs = {}
|
29
|
+
if story_log_extra_data is None:
|
30
|
+
story_log_extra_data = {}
|
31
|
+
|
32
|
+
try:
|
33
|
+
return func(*func_args, **func_kwargs)
|
34
|
+
except Exception as exception:
|
35
|
+
_logger.error(f"Error in {func.__name__}", exc_info=True)
|
36
|
+
|
37
|
+
if story_log_title is None:
|
38
|
+
story_log_title = f"Error in func {func.__name__}: {type(exception).__name__}: {exception}"
|
39
|
+
story_log_extra_data.update({
|
40
|
+
"exception": str(exception),
|
41
|
+
"exception_traceback": exception_to_traceback_str(exception=exception),
|
42
|
+
"exception_type_name": type(exception).__name__
|
43
|
+
})
|
44
|
+
|
45
|
+
if session_ is not None:
|
46
|
+
story_log_dbm = StoryLogDBM(
|
47
|
+
level=story_log_level,
|
48
|
+
type=story_log_type,
|
49
|
+
title=story_log_title,
|
50
|
+
extra_data=story_log_extra_data
|
51
|
+
)
|
52
|
+
session_.add(story_log_dbm)
|
53
|
+
session_.commit()
|
54
|
+
else:
|
55
|
+
with get_cached_sqlalchemy_db().new_session() as session:
|
56
|
+
story_log_dbm = StoryLogDBM(
|
57
|
+
level=story_log_level,
|
58
|
+
type=story_log_type,
|
59
|
+
title=story_log_title,
|
60
|
+
extra_data=story_log_extra_data
|
61
|
+
)
|
62
|
+
session.add(story_log_dbm)
|
63
|
+
session.commit()
|
64
|
+
|
65
|
+
raise exception
|
66
|
+
|
67
|
+
|
68
|
+
def __example():
|
69
|
+
setup_logging()
|
70
|
+
|
71
|
+
def hello_world():
|
72
|
+
print(1)
|
73
|
+
raise ValueError("1111111")
|
74
|
+
|
75
|
+
sync_execute_with_story_log(
|
76
|
+
func=hello_world
|
77
|
+
)
|
78
|
+
|
79
|
+
|
80
|
+
if __name__ == '__main__':
|
81
|
+
__example()
|
@@ -258,11 +258,12 @@ arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model
|
|
258
258
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/api_key.py,sha256=2X6VPkf1TKq-0319J0tL-rPMvgmkBCjim3Si1dZboMQ,1969
|
259
259
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/common.py,sha256=9j3QwBkaQSmsqXZbAYZDysGXP3xPPAHJfqIja5UnLcc,3229
|
260
260
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py,sha256=op5cSkTlHJyGjULgcSWE9-_PNinKSneHLxhG5DUkd9M,5913
|
261
|
-
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=
|
261
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=u4bXqP0tul7wwypWnqSKdvn6N2DJPdmOi_CBy_JMFrk,2482
|
262
262
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py,sha256=-gmBWOAHJsUl-YY7U_2ZcKK5GV9dPHpvpdTRQnfbA_0,7579
|
263
263
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user_token.py,sha256=hX6nHvVvhg5YB3vCjsku4TDoY5Jk1FsuDu5elbcF7VE,1886
|
264
264
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/verification_code.py,sha256=xrrNPXn5PeCnZ2VWVBdXDUft83EEYtc6b4pvs0oh1uw,3078
|
265
265
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
266
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/execute_func_with_story_log.py,sha256=dZxt9y4YCX_8Pu00QojnmfFI4H93-rs8UuSiNT098eA,2499
|
266
267
|
arpakitlib/_arpakit_project_template_v_5/project/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
267
268
|
arpakitlib/_arpakit_project_template_v_5/project/test_data/make_test_api_keys.py,sha256=9F2bMfymaqx_Czh_tF945BKpKqNrVNjSIfCQl13Dkxw,911
|
268
269
|
arpakitlib/_arpakit_project_template_v_5/project/test_data/make_test_data_1.py,sha256=F7vCmfWjItw5QzYR7_OAPSHdJt9louuvqXvcfOkU0AU,2246
|
@@ -406,8 +407,8 @@ arpakitlib/ar_ssh_runner_util.py,sha256=yvAwza480MkHKvLkDEsR7JNh2bYNs6P9rCVo4NA8
|
|
406
407
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
407
408
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
408
409
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
409
|
-
arpakitlib-1.8.
|
410
|
-
arpakitlib-1.8.
|
411
|
-
arpakitlib-1.8.
|
412
|
-
arpakitlib-1.8.
|
413
|
-
arpakitlib-1.8.
|
410
|
+
arpakitlib-1.8.152.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
411
|
+
arpakitlib-1.8.152.dist-info/METADATA,sha256=87EE4vtrA0N8mTZmUnJsr_OdGDe53fCesdp8DoViueM,3706
|
412
|
+
arpakitlib-1.8.152.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
413
|
+
arpakitlib-1.8.152.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
414
|
+
arpakitlib-1.8.152.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|