arpakitlib 1.8.152__py3-none-any.whl → 1.8.155__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,7 +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
+ error_in_execute_with_story_log = "error_in_execute_with_story_log"
29
29
 
30
30
  level: Mapped[str] = mapped_column(
31
31
  sqlalchemy.TEXT,
@@ -1,9 +1,12 @@
1
+ import asyncio
2
+ import inspect
1
3
  import logging
2
- from typing import Callable, Any
4
+ from typing import Any
3
5
 
4
- from arpakitlib.ar_exception_util import exception_to_traceback_str
6
+ from sqlalchemy.ext.asyncio import AsyncSession
5
7
  from sqlalchemy.orm import Session
6
8
 
9
+ from arpakitlib.ar_exception_util import exception_to_traceback_str
7
10
  from project.core.util import setup_logging
8
11
  from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
9
12
  from project.sqlalchemy_db_.sqlalchemy_model import StoryLogDBM
@@ -12,15 +15,15 @@ _logger = logging.getLogger(__name__)
12
15
 
13
16
 
14
17
  def sync_execute_with_story_log(
15
- func: Callable,
18
+ func,
16
19
  *,
17
- func_args: tuple | None = None,
18
- func_kwargs: dict | None = None,
20
+ func_args: tuple[Any] | None = None,
21
+ func_kwargs: dict[Any, Any] | None = None,
19
22
  session_: Session | None = None,
20
23
  story_log_level: str = StoryLogDBM.Levels.error,
21
- story_log_type: str = StoryLogDBM.Types.error_in_sync_execute_with_story_log,
24
+ story_log_type: str = StoryLogDBM.Types.error_in_execute_with_story_log,
22
25
  story_log_title: str | None = None,
23
- story_log_extra_data: dict | None = None,
26
+ story_log_extra_data: dict[Any, Any] | None = None,
24
27
  ) -> Any:
25
28
  if func_args is None:
26
29
  func_args = tuple()
@@ -39,7 +42,8 @@ def sync_execute_with_story_log(
39
42
  story_log_extra_data.update({
40
43
  "exception": str(exception),
41
44
  "exception_traceback": exception_to_traceback_str(exception=exception),
42
- "exception_type_name": type(exception).__name__
45
+ "exception_type_name": type(exception).__name__,
46
+ "func_name": inspect.currentframe().f_code.co_name
43
47
  })
44
48
 
45
49
  if session_ is not None:
@@ -65,17 +69,82 @@ def sync_execute_with_story_log(
65
69
  raise exception
66
70
 
67
71
 
68
- def __example():
72
+ async def async_execute_with_story_log(
73
+ async_func,
74
+ *,
75
+ async_func_args: tuple[Any] | None = None,
76
+ async_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 async_func_args is None:
84
+ async_func_args = ()
85
+ if async_func_kwargs is None:
86
+ async_func_kwargs = {}
87
+ if story_log_extra_data is None:
88
+ story_log_extra_data = {}
89
+
90
+ try:
91
+ return await async_func(*async_func_args, **async_func_kwargs)
92
+ except Exception as exception:
93
+ _logger.error(f"Async error in {async_func.__name__}", exc_info=True)
94
+
95
+ if story_log_title is None:
96
+ story_log_title = f"Async error in func {async_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():
69
129
  setup_logging()
70
130
 
71
131
  def hello_world():
72
- print(1)
73
- raise ValueError("1111111")
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")
74
140
 
75
- sync_execute_with_story_log(
76
- func=hello_world
77
- )
141
+ # sync_execute_with_story_log(
142
+ # func=hello_world
143
+ # )
144
+ # await async_execute_with_story_log(
145
+ # func=async_hello_world
146
+ # )
78
147
 
79
148
 
80
149
  if __name__ == '__main__':
81
- __example()
150
+ asyncio.run(__async_example())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: arpakitlib
3
- Version: 1.8.152
3
+ Version: 1.8.155
4
4
  Summary: arpakitlib
5
5
  License: Apache-2.0
6
6
  Keywords: arpakitlib,arpakit,arpakit-company,arpakitcompany,arpakit_company
@@ -258,12 +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=u4bXqP0tul7wwypWnqSKdvn6N2DJPdmOi_CBy_JMFrk,2482
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=dZxt9y4YCX_8Pu00QojnmfFI4H93-rs8UuSiNT098eA,2499
266
+ arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/execute_func_with_story_log.py,sha256=TVdhSL7g_L6tW5-DSZTFUJbCQtXlv2Fs_A6PaLZawdQ,5057
267
267
  arpakitlib/_arpakit_project_template_v_5/project/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
268
268
  arpakitlib/_arpakit_project_template_v_5/project/test_data/make_test_api_keys.py,sha256=9F2bMfymaqx_Czh_tF945BKpKqNrVNjSIfCQl13Dkxw,911
269
269
  arpakitlib/_arpakit_project_template_v_5/project/test_data/make_test_data_1.py,sha256=F7vCmfWjItw5QzYR7_OAPSHdJt9louuvqXvcfOkU0AU,2246
@@ -407,8 +407,8 @@ arpakitlib/ar_ssh_runner_util.py,sha256=yvAwza480MkHKvLkDEsR7JNh2bYNs6P9rCVo4NA8
407
407
  arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
408
408
  arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
409
409
  arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
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,,
410
+ arpakitlib-1.8.155.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
411
+ arpakitlib-1.8.155.dist-info/METADATA,sha256=QKV0wMCBp4PPJHanz2EEe30ZmJyGGfrt_Tt3wdP7Gq4,3706
412
+ arpakitlib-1.8.155.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
413
+ arpakitlib-1.8.155.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
414
+ arpakitlib-1.8.155.dist-info/RECORD,,