This commit is contained in:
Your Name
2026-08-26 17:18:09 +08:00
parent 327a0bc42f
commit 4ac6990efe
20 changed files with 1336 additions and 130 deletions
+38 -1
View File
@@ -33,6 +33,7 @@ from rpa_engine.runtime_config import (
ensure_browser_display,
playwright_proxy,
)
from rpa_engine.egress_channels import clamp_attempts, resolve_fixed_channel
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
logger = logging.getLogger("rpa_engine")
@@ -909,6 +910,42 @@ class DouyinWorker:
async def _run_im_direct_service(self, session: DouyinImSession):
"""运行 IM API + WebSocket 直连自动回复"""
# 公网通道配置独立存于账号表。固定通道在启动时解析一次供 WS 使用;
# HTTP 发送仍会在每次建连时校验,账号编辑后的配置无需重启即可生效。
row = None
db = await self.get_db()
try:
try:
row = (
await db.execute(
select(
Account.egress_public_ip,
Account.egress_auto_attempts,
).where(Account.id == self.account_id)
)
).one_or_none()
except Exception as exc:
# A worker may be created by an isolated test or during a
# rolling deployment before the startup migration finishes.
logger.debug("load account egress config failed: %s", exc)
finally:
await db.close()
session.egress_public_ip = str((row.egress_public_ip if row else "") or "").strip()
session.egress_auto_attempts = clamp_attempts(
row.egress_auto_attempts if row else 1
)
session.egress_source_ip = ""
if session.egress_public_ip:
try:
route = await resolve_fixed_channel(session.egress_public_ip)
session.egress_source_ip = str(route.source_ip or "")
except Exception as exc:
logger.warning(
"Account %s selected egress %s is not currently resolvable: %s",
self.account_id,
session.egress_public_ip,
exc,
)
# Cache the only account fields needed by the follow-welcome timer.
# Disabled accounts subsequently avoid the old full Account query on
# every minute tick.
@@ -925,7 +962,7 @@ class DouyinWorker:
reply_delay_resolver=self.resolve_reply_delay_seconds,
# 关注欢迎语:周期性检测新粉丝并自动私信(约每 60s)
follow_tick=self.follow_welcome_tick,
# IM 登录失效(INVALID_REQUEST)时自动下线
# IM 登录失效(INVALID_REQUEST/KICK)时自动下线
on_session_invalid=self.on_im_session_invalid,
# Batch admission waits for UID/frontier/WS/first-poll completion;
# it no longer releases its slot immediately after create_task().