feat: sync runtime multi-user web and login updates

This commit is contained in:
Rixuan Shao
2026-08-17 23:16:12 +08:00
parent 846ce88daf
commit ee441ff5a1
23 changed files with 1879 additions and 198 deletions
+16 -4
View File
@@ -141,7 +141,21 @@ async def _wait_for_first_friend_or_empty(page):
return False
async def _wait_for_chat_or_login(page, timeout_seconds=30):
deadline = asyncio.get_running_loop().time() + timeout_seconds
while asyncio.get_running_loop().time() < deadline:
await _ensure_logged_in(page)
try:
if await page.locator("#sub-app").count() > 0:
return
except Exception:
pass
await asyncio.sleep(0.5)
raise RuntimeError("chat page did not load within timeout")
async def collect_friend_names(page):
await _wait_for_chat_or_login(page)
await _click_friends_tab(page)
await asyncio.sleep(1)
@@ -217,12 +231,10 @@ async def fetch_account_friends(account):
context.set_default_timeout(120000)
page = await context.new_page()
await page.goto("https://creator.douyin.com/", wait_until="domcontentloaded", timeout=60000)
await context.add_cookies(cookies)
await page.goto(CHAT_PAGE_URL, wait_until="domcontentloaded", timeout=60000)
await asyncio.sleep(2)
await page.goto(CHAT_PAGE_URL, wait_until="commit", timeout=30000)
await asyncio.sleep(1)
await _ensure_logged_in(page)
friends = await collect_friend_names(page)
return friends
except RuntimeError:
+10
View File
@@ -1625,6 +1625,13 @@ def _manual_run_unsent_only():
return _is_manual_run() and os.getenv("SPARKFLOW_MANUAL_UNSENT_ONLY") == "1"
def _requested_account_refs():
raw = os.getenv("SPARKFLOW_ACCOUNT_REFS")
if raw is None:
return None
return {item.strip() for item in raw.split(",") if item.strip()}
def _unsent_retry_max_attempts():
raw_value = str(os.getenv("SPARKFLOW_UNSENT_RETRY_MAX_ATTEMPTS") or "3").strip()
try:
@@ -2719,6 +2726,9 @@ async def _do_user_task_locked(browser, user, send_strategy, profile_config, fri
async def runTasks():
active_config = get_config(force_reload=True)
all_user_data = get_userData(force_reload=True)
requested_refs = _requested_account_refs()
if requested_refs is not None:
all_user_data = [user for user in all_user_data if user.get("account_ref") in requested_refs]
active_user_data = [user for user in all_user_data if user.get("enabled", True)]
disabled_user_data = [user for user in all_user_data if not user.get("enabled", True)]