ezKit 3.0.3__tar.gz → 3.0.4__tar.gz
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.
- {ezkit-3.0.3/ezKit.egg-info → ezkit-3.0.4}/PKG-INFO +1 -1
- {ezkit-3.0.3 → ezkit-3.0.4}/README.md +3 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit/utils.py +56 -2
- {ezkit-3.0.3 → ezkit-3.0.4/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.3 → ezkit-3.0.4}/setup.py +1 -1
- {ezkit-3.0.3 → ezkit-3.0.4}/LICENSE +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/MANIFEST.in +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit/__init__.py +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit/database.py +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/pyproject.toml +0 -0
- {ezkit-3.0.3 → ezkit-3.0.4}/setup.cfg +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"""Utils Library"""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import time
|
|
4
5
|
from functools import wraps
|
|
5
6
|
from os import environ
|
|
6
7
|
from pathlib import Path
|
|
7
|
-
from typing import Any, Callable, ParamSpec, TypeVar
|
|
8
|
+
from typing import Any, Callable, Coroutine, ParamSpec, TypeVar
|
|
8
9
|
|
|
9
10
|
from loguru import logger
|
|
10
11
|
|
|
@@ -66,16 +67,28 @@ R = TypeVar("R")
|
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
def retry_decorator(times: int = 3, delay: float = 1.0):
|
|
69
|
-
"""重试装饰器
|
|
70
|
+
"""重试装饰器
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
times: 最大重试次数
|
|
74
|
+
delay: 每次重试之间的等待时间(秒)
|
|
75
|
+
"""
|
|
70
76
|
|
|
71
77
|
def decorator(func: Callable[P, R]) -> Callable[P, R | bool]:
|
|
78
|
+
|
|
72
79
|
@wraps(func)
|
|
73
80
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R | bool:
|
|
81
|
+
|
|
74
82
|
max_times = max(1, times)
|
|
83
|
+
|
|
75
84
|
for attempt in range(max_times):
|
|
85
|
+
|
|
76
86
|
try:
|
|
87
|
+
|
|
77
88
|
return func(*args, **kwargs)
|
|
89
|
+
|
|
78
90
|
except Exception as e:
|
|
91
|
+
|
|
79
92
|
if DEBUG:
|
|
80
93
|
logger.exception(e)
|
|
81
94
|
else:
|
|
@@ -85,6 +98,47 @@ def retry_decorator(times: int = 3, delay: float = 1.0):
|
|
|
85
98
|
time.sleep(delay)
|
|
86
99
|
else:
|
|
87
100
|
return False
|
|
101
|
+
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
return wrapper
|
|
105
|
+
|
|
106
|
+
return decorator
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def async_retry_decorator(times: int = 3, delay: float = 1.0):
|
|
110
|
+
"""异步重试装饰器
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
times: 最大重试次数
|
|
114
|
+
delay: 每次重试之间的等待时间(秒)
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
def decorator(func: Callable[P, Coroutine[Any, Any, R]]) -> Callable[P, Coroutine[Any, Any, R | bool]]:
|
|
118
|
+
|
|
119
|
+
@wraps(func)
|
|
120
|
+
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R | bool:
|
|
121
|
+
|
|
122
|
+
max_times = max(1, times)
|
|
123
|
+
|
|
124
|
+
for attempt in range(max_times):
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
|
|
128
|
+
return await func(*args, **kwargs)
|
|
129
|
+
|
|
130
|
+
except Exception as e:
|
|
131
|
+
|
|
132
|
+
if DEBUG:
|
|
133
|
+
logger.exception(e)
|
|
134
|
+
else:
|
|
135
|
+
logger.error(e)
|
|
136
|
+
|
|
137
|
+
if attempt < (max_times - 1):
|
|
138
|
+
await asyncio.sleep(delay)
|
|
139
|
+
else:
|
|
140
|
+
return False
|
|
141
|
+
|
|
88
142
|
return False
|
|
89
143
|
|
|
90
144
|
return wrapper
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|