arpakitlib 1.8.151__py3-none-any.whl → 1.8.154__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.
@@ -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_execute_with_story_log = "error_in_execute_with_story_log"
28
29
 
29
30
  level: Mapped[str] = mapped_column(
30
31
  sqlalchemy.TEXT,
@@ -0,0 +1,150 @@
1
+ import asyncio
2
+ import inspect
3
+ import logging
4
+ from typing import Any
5
+
6
+ from sqlalchemy.ext.asyncio import AsyncSession
7
+ from sqlalchemy.orm import Session
8
+
9
+ from arpakitlib.ar_exception_util import exception_to_traceback_str
10
+ from project.core.util import setup_logging
11
+ from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
12
+ from project.sqlalchemy_db_.sqlalchemy_model import StoryLogDBM
13
+
14
+ _logger = logging.getLogger(__name__)
15
+
16
+
17
+ def sync_execute_with_story_log(
18
+ func,
19
+ *,
20
+ func_args: tuple[Any] | None = None,
21
+ func_kwargs: dict[Any, Any] | None = None,
22
+ session_: Session | None = None,
23
+ story_log_level: str = StoryLogDBM.Levels.error,
24
+ story_log_type: str = StoryLogDBM.Types.error_in_execute_with_story_log,
25
+ story_log_title: str | None = None,
26
+ story_log_extra_data: dict[Any, Any] | None = None,
27
+ ) -> Any:
28
+ if func_args is None:
29
+ func_args = tuple()
30
+ if func_kwargs is None:
31
+ func_kwargs = {}
32
+ if story_log_extra_data is None:
33
+ story_log_extra_data = {}
34
+
35
+ try:
36
+ return func(*func_args, **func_kwargs)
37
+ except Exception as exception:
38
+ _logger.error(f"Error in {func.__name__}", exc_info=True)
39
+
40
+ if story_log_title is None:
41
+ story_log_title = f"Error in func {func.__name__}: {type(exception).__name__}: {exception}"
42
+ story_log_extra_data.update({
43
+ "exception": str(exception),
44
+ "exception_traceback": exception_to_traceback_str(exception=exception),
45
+ "exception_type_name": type(exception).__name__,
46
+ "func_name": inspect.currentframe().f_code.co_name
47
+ })
48
+
49
+ if session_ is not None:
50
+ story_log_dbm = StoryLogDBM(
51
+ level=story_log_level,
52
+ type=story_log_type,
53
+ title=story_log_title,
54
+ extra_data=story_log_extra_data
55
+ )
56
+ session_.add(story_log_dbm)
57
+ session_.commit()
58
+ else:
59
+ with get_cached_sqlalchemy_db().new_session() as session:
60
+ story_log_dbm = StoryLogDBM(
61
+ level=story_log_level,
62
+ type=story_log_type,
63
+ title=story_log_title,
64
+ extra_data=story_log_extra_data
65
+ )
66
+ session.add(story_log_dbm)
67
+ session.commit()
68
+
69
+ raise exception
70
+
71
+
72
+ async def async_execute_with_story_log(
73
+ func,
74
+ *,
75
+ func_args: tuple[Any] | None = None,
76
+ func_kwargs: dict[Any, Any] | None = None,
77
+ async_session_: AsyncSession | None = None,
78
+ story_log_level: str = StoryLogDBM.Levels.error,
79
+ story_log_type: str = StoryLogDBM.Types.error_in_execute_with_story_log,
80
+ story_log_title: str | None = None,
81
+ story_log_extra_data: dict[Any, Any] | None = None,
82
+ ) -> Any:
83
+ if func_args is None:
84
+ func_args = ()
85
+ if func_kwargs is None:
86
+ func_kwargs = {}
87
+ if story_log_extra_data is None:
88
+ story_log_extra_data = {}
89
+
90
+ try:
91
+ return await func(*func_args, **func_kwargs)
92
+ except Exception as exception:
93
+ _logger.error(f"Async error in {func.__name__}", exc_info=True)
94
+
95
+ if story_log_title is None:
96
+ story_log_title = f"Async error in func {func.__name__}: {type(exception).__name__}: {exception}"
97
+
98
+ story_log_extra_data.update({
99
+ "exception": str(exception),
100
+ "exception_traceback": exception_to_traceback_str(exception=exception),
101
+ "exception_type_name": type(exception).__name__,
102
+ "func_name": inspect.currentframe().f_code.co_name
103
+ })
104
+
105
+ if async_session_ is not None:
106
+ story_log_dbm = StoryLogDBM(
107
+ level=story_log_level,
108
+ type=story_log_type,
109
+ title=story_log_title,
110
+ extra_data=story_log_extra_data
111
+ )
112
+ async_session_.add(story_log_dbm)
113
+ await async_session_.commit()
114
+ else:
115
+ async with get_cached_sqlalchemy_db().new_async_session() as async_session:
116
+ story_log_dbm = StoryLogDBM(
117
+ level=story_log_level,
118
+ type=story_log_type,
119
+ title=story_log_title,
120
+ extra_data=story_log_extra_data
121
+ )
122
+ async_session.add(story_log_dbm)
123
+ await async_session.commit()
124
+
125
+ raise exception
126
+
127
+
128
+ async def __async_example():
129
+ setup_logging()
130
+
131
+ def hello_world():
132
+ print(inspect.currentframe().f_code.co_name)
133
+ # raise ValueError("1111111")
134
+
135
+ print(hello_world())
136
+
137
+ # async def async_hello_world():
138
+ # print(1)
139
+ # raise ValueError("1111111")
140
+
141
+ # sync_execute_with_story_log(
142
+ # func=hello_world
143
+ # )
144
+ # await async_execute_with_story_log(
145
+ # func=async_hello_world
146
+ # )
147
+
148
+
149
+ if __name__ == '__main__':
150
+ asyncio.run(__async_example())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: arpakitlib
3
- Version: 1.8.151
3
+ Version: 1.8.154
4
4
  Summary: arpakitlib
5
5
  License: Apache-2.0
6
6
  Keywords: arpakitlib,arpakit,arpakit-company,arpakitcompany,arpakit_company
@@ -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=wig_D6OZyYYGsqZEbmSK56qoAIOnOVnOEB_sRSZLSIU,2396
261
+ arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=hMYVJq837ZeIO3J2neOAzuzxeZ7hdR5PY93-YdgHftU,2472
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=nAbcbBVUkToZioyVKaiOM0d1mHP0yy4THnLOjf2zjTg,4985
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.151.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
410
- arpakitlib-1.8.151.dist-info/METADATA,sha256=T9_jeYVGKoFTFcemqy-G9dIK_pf7x0fL4r1G8mJE9kI,3706
411
- arpakitlib-1.8.151.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
412
- arpakitlib-1.8.151.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
413
- arpakitlib-1.8.151.dist-info/RECORD,,
410
+ arpakitlib-1.8.154.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
411
+ arpakitlib-1.8.154.dist-info/METADATA,sha256=j35xSpxIIkT96WiRVw0u3aeerw04TZfQdoEL2rbyQ2w,3706
412
+ arpakitlib-1.8.154.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
413
+ arpakitlib-1.8.154.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
414
+ arpakitlib-1.8.154.dist-info/RECORD,,