🔧 添加超时配置项

This commit is contained in:
洛水居室 2022-10-22 15:48:53 +08:00
parent 8c8e09be7b
commit 465f7c4148
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
3 changed files with 21 additions and 1 deletions

View File

@ -46,6 +46,13 @@ LOGGER_LOCALS_MAX_DEPTH=0
LOGGER_LOCALS_MAX_LENGTH=10 LOGGER_LOCALS_MAX_LENGTH=10
LOGGER_LOCALS_MAX_STRING=80 LOGGER_LOCALS_MAX_STRING=80
# 超时配置 可选配置项
# TIMEOUT = 10
# READ_TIMEOUT = 2
# WRITE_TIMEOUT = 10
# CONNECT_TIMEOUT = 10
# POOL_TIMEOUT = 10
# mtp 客户端 可选配置项 # mtp 客户端 可选配置项
# API_ID=12345 # API_ID=12345
# API_HASH="abcdefg" # API_HASH="abcdefg"

View File

@ -243,7 +243,14 @@ class Bot:
try: try:
for _ in range(5): for _ in range(5):
try: try:
self.app.run_polling(close_loop=False, write_timeout=10) self.app.run_polling(
close_loop=False,
timeout=self.config.timeout,
read_timeout=self.config.read_timeout,
write_timeout=self.config.write_timeout,
connect_timeout=self.config.connect_timeout,
pool_timeout=self.config.pool_timeout,
)
break break
except TimedOut: except TimedOut:
logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={"markup": True}) logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={"markup": True})

View File

@ -57,6 +57,12 @@ class BotConfig(BaseSettings):
logger_locals_max_length: int = 10 logger_locals_max_length: int = 10
logger_locals_max_string: int = 80 logger_locals_max_string: int = 80
timeout: int = 10
read_timeout: float = 2
write_timeout: Optional[float] = None
connect_timeout: Optional[float] = None
pool_timeout: Optional[float] = None
enka_network_api_agent: str = "" enka_network_api_agent: str = ""
pass_challenge_api: str = "" pass_challenge_api: str = ""
pass_challenge_app_key: str = "" pass_challenge_app_key: str = ""