first init

This commit is contained in:
xingc
2025-02-18 14:26:47 +08:00
commit 48a02974fc
41 changed files with 2297 additions and 0 deletions

6
core/utils/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding = utf-8 -*-
# @Time : 2025/2/13 下午5:42
# @File : __init__.py.py
# @Software : PyCharm
# @Author : xingc
# @Desc :

34
core/utils/helper.py Normal file
View File

@@ -0,0 +1,34 @@
# -*- coding = utf-8 -*-
# @Time : 2025/2/13 下午7:40
# @File : helper.py
# @Software : PyCharm
# @Author : xingc
# @Desc :
import asyncio
import functools
from typing import Callable
def async_retry(max_retries: int = 3, exceptions: tuple = (Exception,)):
"""
异步重试装饰器。
:param max_retries: 最大重试次数。
:param exceptions: 触发重试的异常类型。
"""
def decorator(func: Callable):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
retries = 0
while retries < max_retries:
try:
return await func(*args, **kwargs)
except exceptions as e:
retries += 1
if retries >= max_retries:
raise # 如果达到最大重试次数,抛出异常
return wrapper
return decorator

6
core/utils/response.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding = utf-8 -*-
# @Time : 2025/2/13 下午5:43
# @File : response.py
# @Software : PyCharm
# @Author : xingc
# @Desc :