🎨 Update Networking backend tweaks

This commit is contained in:
洛水居室 2023-02-19 20:40:27 +08:00 committed by GitHub
parent f564a1db02
commit 9d8d6deda7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 12 deletions

View File

@ -50,13 +50,21 @@ LOGGER_LOCALS_MAX_STRING=80
# 可被 logger 打印的 record 的名称(默认包含了 LOGGER_NAME
LOGGER_FILTERED_NAMES=["uvicorn","ErrorPush","ApiHelper"]
# 超时配置 可选配置项
# TIMEOUT = 10
# READ_TIMEOUT = 2
# Request 超时配置 可选配置项
# READ_TIMEOUT=7
# 指定等待服务器响应的最长时间
# WRITE_TIMEOUT=10
# 指定等待写入操作完成的最长时间(就网络套接字而言,即请求或上传一个文件)
# CONNECT_TIMEOUT=10
# 指定等待连接到服务器的最长时间
# POOL_TIMEOUT=10
# Bot.Update 超时配置
# TIMEOUT=10
# 服务器出现故障时Updater的引导阶段重试时间
# UPDATE_READ_TIMEOUT=42
# UPDATE_WRITE_TIMEOUT=10
# UPDATE_CONNECT_TIMEOUT=10
# UPDATE_POOL_TIMEOUT=10
# genshin.py 缓存配置 可选配置项
# GENSHIN_TTL = 3600

View File

@ -259,6 +259,14 @@ class Bot:
logger.info("正在初始化BOT")
self.app = (
TgApplication.builder()
.read_timeout(self.config.read_timeout)
.write_timeout(self.config.write_timeout)
.connect_timeout(self.config.connect_timeout)
.pool_timeout(self.config.pool_timeout)
.get_updates_read_timeout(self.config.update_read_timeout)
.get_updates_write_timeout(self.config.update_write_timeout)
.get_updates_connect_timeout(self.config.update_connect_timeout)
.get_updates_pool_timeout(self.config.update_pool_timeout)
.rate_limiter(AIORateLimiter())
.defaults(Defaults(tzinfo=pytz.timezone("Asia/Shanghai")))
.token(self._config.bot_token)
@ -271,10 +279,6 @@ class Bot:
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,
allowed_updates=Update.ALL_TYPES,
)
break

View File

@ -122,10 +122,14 @@ class BotConfig(Settings):
join_groups: Optional[JoinGroups] = JoinGroups.NO_ALLOW
timeout: int = 10
read_timeout: float = 2
read_timeout: Optional[float] = None
write_timeout: Optional[float] = None
connect_timeout: Optional[float] = None
pool_timeout: Optional[float] = None
update_read_timeout: Optional[float] = None
update_write_timeout: Optional[float] = None
update_connect_timeout: Optional[float] = None
update_pool_timeout: Optional[float] = None
genshin_ttl: Optional[int] = None