arpakitlib 1.8.176__py3-none-any.whl → 1.8.178__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/arpakitlib_project_template_info.json +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py +2 -0
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py +2 -0
- arpakitlib/ar_safe_func.py +65 -0
- {arpakitlib-1.8.176.dist-info → arpakitlib-1.8.178.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.176.dist-info → arpakitlib-1.8.178.dist-info}/RECORD +9 -8
- {arpakitlib-1.8.176.dist-info → arpakitlib-1.8.178.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.176.dist-info → arpakitlib-1.8.178.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.176.dist-info → arpakitlib-1.8.178.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
# arpakit
|
2
|
+
import datetime as dt
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
from pydantic import BaseModel, ConfigDict
|
6
|
+
|
7
|
+
from arpakitlib.ar_datetime_util import now_utc_dt
|
8
|
+
|
9
|
+
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
10
|
+
|
11
|
+
|
12
|
+
class SafeFuncResult(BaseModel):
|
13
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
14
|
+
|
15
|
+
has_exception: bool = False
|
16
|
+
func_result: Any = None
|
17
|
+
exception: Exception | None = None
|
18
|
+
duration: dt.timedelta | None = None
|
19
|
+
|
20
|
+
def simple_dict_for_json(self) -> dict[str, Any]:
|
21
|
+
return {
|
22
|
+
"has_exception": self.has_exception,
|
23
|
+
"func_result": self.func_result,
|
24
|
+
"exception": self.exception,
|
25
|
+
"duration": self.duration,
|
26
|
+
"duration_total_seconds": self.duration.total_seconds() if self.duration is not None else None
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
def sync_safely_run_func(*, sync_func, args: tuple | None = None, kwargs: dict | None = None) -> SafeFuncResult:
|
31
|
+
if args is None:
|
32
|
+
args = tuple()
|
33
|
+
if kwargs is None:
|
34
|
+
kwargs = {}
|
35
|
+
func_start_dt = now_utc_dt()
|
36
|
+
try:
|
37
|
+
res = sync_func(*args, **kwargs)
|
38
|
+
duration = now_utc_dt() - func_start_dt
|
39
|
+
return SafeFuncResult(
|
40
|
+
has_exception=True,
|
41
|
+
func_result=res,
|
42
|
+
duration=duration
|
43
|
+
)
|
44
|
+
except Exception as exception:
|
45
|
+
return SafeFuncResult(
|
46
|
+
has_exception=False,
|
47
|
+
exception=exception
|
48
|
+
)
|
49
|
+
|
50
|
+
|
51
|
+
def __example():
|
52
|
+
def div(a: int, b: int) -> float:
|
53
|
+
return a / b
|
54
|
+
|
55
|
+
# успешный вызов
|
56
|
+
ok_result = sync_safely_run_func(sync_func=div, args=(10, 2))
|
57
|
+
print("OK result:", ok_result.model_dump())
|
58
|
+
|
59
|
+
# вызов с исключением
|
60
|
+
err_result = sync_safely_run_func(sync_func=div, args=(10, 0))
|
61
|
+
print("ERR result:", err_result.model_dump())
|
62
|
+
|
63
|
+
|
64
|
+
if __name__ == "__main__":
|
65
|
+
__example()
|
@@ -8,7 +8,7 @@ arpakitlib/_arpakit_project_template_v_5/alembic/env.py,sha256=Qesmnj5A2kB-Doeuf
|
|
8
8
|
arpakitlib/_arpakit_project_template_v_5/alembic/script.py.mako,sha256=MEqL-2qATlST9TAOeYgscMn1uy6HUS9NFvDgl93dMj8,635
|
9
9
|
arpakitlib/_arpakit_project_template_v_5/alembic/versions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
arpakitlib/_arpakit_project_template_v_5/alembic.ini,sha256=8fuyeEvGBiPGbxEFy8ISBV3xX_fgVmuhEGpB10_B5Uo,3733
|
11
|
-
arpakitlib/_arpakit_project_template_v_5/arpakitlib_project_template_info.json,sha256=
|
11
|
+
arpakitlib/_arpakit_project_template_v_5/arpakitlib_project_template_info.json,sha256=UOSnIA-VRLPGmdqmBcYXowKrqqdwsQTzB5CRgItzj7E,98
|
12
12
|
arpakitlib/_arpakit_project_template_v_5/command/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
arpakitlib/_arpakit_project_template_v_5/command/alembic_history.sh,sha256=OMnDNtHIksGh9iavWnzbtxcudZW4vjdcISsBXvzZSPw,22
|
14
14
|
arpakitlib/_arpakit_project_template_v_5/command/alembic_revision_autogenerate.sh,sha256=yW2i-SBOtBx15Ya0poVQqKkJM5t2JZp06r9AEW-DmGE,46
|
@@ -262,8 +262,8 @@ arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_db.py
|
|
262
262
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/__init__.py,sha256=zRK-ao92u6Q-NNTtsPycTVEjzRjK5BOXgsUZRtNblpM,688
|
263
263
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/api_key.py,sha256=2X6VPkf1TKq-0319J0tL-rPMvgmkBCjim3Si1dZboMQ,1969
|
264
264
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/common.py,sha256=9j3QwBkaQSmsqXZbAYZDysGXP3xPPAHJfqIja5UnLcc,3229
|
265
|
-
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py,sha256=
|
266
|
-
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=
|
265
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py,sha256=emIo83GUEoywgh4fGv2xDGIkCtSUPq_2ujRlLEc5woM,5930
|
266
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=CiNec-x5_z0Pr5Mt-RZXJ1tKJMRn_TAKIaOioG4NK7U,2489
|
267
267
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py,sha256=22TE8y2Vm9byLLkIE6RVAMa29d9ILCVg1e1QYi4ONIQ,7898
|
268
268
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user_token.py,sha256=dCCiRZcOiUpqd-DZZ-A6tVM0PzJwa030KFOzPXNyM7A,1929
|
269
269
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/verification_code.py,sha256=3fNkUwWEdt6l3Snwr_ktMqzTeo2hm04hPlznCLr2izg,3548
|
@@ -403,6 +403,7 @@ arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJ
|
|
403
403
|
arpakitlib/ar_rat_func_util.py,sha256=Ca10o3RJwyx_DJLxjTxgHDO6NU3M6CWgUR4bif67OE4,2006
|
404
404
|
arpakitlib/ar_retry_func_util.py,sha256=LB4FJRsu2cssnPw6X8bCEcaGpQsXhkLkgeU37w1t9fU,2250
|
405
405
|
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
406
|
+
arpakitlib/ar_safe_func.py,sha256=7r2ohFfTV-ElJpB-vQ6EcjDYp6jOxv14WepgMK4FDc8,1864
|
406
407
|
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=rXI2_3OTaIBgR-GixM1Ti-Ue1f9nOcO3EUpYRqdGpYM,6973
|
407
408
|
arpakitlib/ar_settings_util.py,sha256=Y5wi_cmsjDjfJpM0VJHjbo0NoVPKfypKaD1USowwDtQ,1327
|
408
409
|
arpakitlib/ar_sleep_util.py,sha256=ggaj7ML6QK_ADsHMcyu6GUmUpQ_9B9n-SKYH17h-9lM,1045
|
@@ -411,8 +412,8 @@ arpakitlib/ar_sqlalchemy_util.py,sha256=w_tGPTWIMVjHkTEYo9tVe1sfK_4vvfd3zGATLiYC
|
|
411
412
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
412
413
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
413
414
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
414
|
-
arpakitlib-1.8.
|
415
|
-
arpakitlib-1.8.
|
416
|
-
arpakitlib-1.8.
|
417
|
-
arpakitlib-1.8.
|
418
|
-
arpakitlib-1.8.
|
415
|
+
arpakitlib-1.8.178.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
416
|
+
arpakitlib-1.8.178.dist-info/METADATA,sha256=qRBO_gvhRvQT5FSveMTijDU9XnXor4ifjl_J4dsa2aE,3741
|
417
|
+
arpakitlib-1.8.178.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
418
|
+
arpakitlib-1.8.178.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
419
|
+
arpakitlib-1.8.178.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|