fix: 增加MySQL重试机制中的错误代码2003并调整相关逻辑
This commit is contained in:
parent
ecfd2d227a
commit
65bff54ce8
5
DB.py
5
DB.py
@ -93,7 +93,7 @@ video_author = Table(
|
||||
|
||||
|
||||
def mysql_retry(max_retries: int = 3, base_delay: float = 10):
|
||||
RETRIABLE_ERRORS = {2013, 1213, 2006, 1205} # 增加 1205
|
||||
RETRIABLE_ERRORS = {2003, 2013, 1213, 2006, 1205} # 增加 1205
|
||||
|
||||
def decorator(fn):
|
||||
@functools.wraps(fn)
|
||||
@ -109,6 +109,7 @@ def mysql_retry(max_retries: int = 3, base_delay: float = 10):
|
||||
raise
|
||||
|
||||
reason = {
|
||||
2003: "无法连接数据库(超时)",
|
||||
2013: "连接断开",
|
||||
1213: "死锁冲突",
|
||||
2006: "连接失效",
|
||||
@ -119,7 +120,7 @@ def mysql_retry(max_retries: int = 3, base_delay: float = 10):
|
||||
logger.warning(
|
||||
f"[MySQL][{fn.__name__}] 第{attempt}次重试({errno} {reason}):{e},等待 {wait:.1f}s...")
|
||||
|
||||
if errno in {2013, 2006}:
|
||||
if errno in {2003, 2013, 2006}:
|
||||
self._reconnect_mysql()
|
||||
if errno == 1205:
|
||||
wait = base_delay + 5 # 比如锁等待固定加一点延迟
|
||||
|
Loading…
x
Reference in New Issue
Block a user