fix(douyu): 修复斗鱼链路 P0/P1 隐患并增强 P2 运维队列可观测性
This commit is contained in:
@@ -9,7 +9,7 @@ import time
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from typing import Any
|
||||
from typing import Any, Self
|
||||
|
||||
import requests
|
||||
|
||||
@@ -80,6 +80,7 @@ class FishFinRechargeClient:
|
||||
):
|
||||
config.validate()
|
||||
self.config = config
|
||||
self._owns_session = session is None
|
||||
self.session = session or requests.Session()
|
||||
self.session.trust_env = False
|
||||
self.trace = trace or (lambda _event: None)
|
||||
@@ -318,3 +319,16 @@ class FishFinRechargeClient:
|
||||
def account_info(self) -> dict[str, Any]:
|
||||
"""查询商户账户信息。"""
|
||||
return self._request("GET", self.USER_INFO_PATH)
|
||||
|
||||
def close(self) -> None:
|
||||
"""关闭自建 HTTP 会话,释放连接池。"""
|
||||
if getattr(self, "_owns_session", False):
|
||||
close = getattr(self.session, "close", None)
|
||||
if callable(close):
|
||||
close()
|
||||
|
||||
def __enter__(self) -> Self:
|
||||
return self
|
||||
|
||||
def __exit__(self, *_exc: object) -> None:
|
||||
self.close()
|
||||
|
||||
Reference in New Issue
Block a user