mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
收窄熔断判断范围,修改熔断逻辑 (#2145)
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, fields
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -101,6 +102,22 @@ def _warn_invalid_env(env_name: str, raw: str, exc: Exception) -> None:
|
||||
return
|
||||
|
||||
|
||||
def _default_passive_db_limit() -> int:
|
||||
try:
|
||||
from zhenxun.configs.config import BotConfig
|
||||
|
||||
scheme = urlparse(BotConfig.db_url or "").scheme.lower()
|
||||
except Exception:
|
||||
scheme = ""
|
||||
if scheme == "sqlite":
|
||||
return 1
|
||||
if scheme.startswith("postgres"):
|
||||
return 6
|
||||
if scheme == "mysql":
|
||||
return 4
|
||||
return 2
|
||||
|
||||
|
||||
def _load_config(cls: type, prefix: str):
|
||||
values = {}
|
||||
default_obj = cls()
|
||||
@@ -115,6 +132,9 @@ def _load_config(cls: type, prefix: str):
|
||||
raw = candidate_value
|
||||
break
|
||||
if raw is None or not raw.strip():
|
||||
if cls is AuthDispatchRuntimeConfig and item.name == "passive_db_limit":
|
||||
values[item.name] = _default_passive_db_limit()
|
||||
continue
|
||||
values[item.name] = default
|
||||
continue
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user