This commit is contained in:
huangzhenpc
2025-04-01 18:38:16 +08:00
parent 221d7d79f1
commit 31fe73f998
2 changed files with 30 additions and 6 deletions

View File

@@ -268,14 +268,18 @@ class AutoCursorService:
imported = await self.import_email_accounts(accounts) imported = await self.import_email_accounts(accounts)
total_imported += imported total_imported += imported
# 导入后等待一秒,确保数据库状态完全更新
logger.debug("等待数据库状态更新...")
await asyncio.sleep(2)
# 每次获取到新邮箱并成功导入后,立即确保注册进程在运行 # 每次获取到新邮箱并成功导入后,立即确保注册进程在运行
if imported > 0 and self.reg_enabled: if imported > 0 and self.reg_enabled:
new_count = pending_count + imported # 重新查询一次确保数据是最新的
if new_count >= self.min_email_to_process: pending_count = await self.count_pending_accounts()
logger.info(f"已获取到 {imported} 个新邮箱,总可用邮箱数 {new_count},确保注册进程运行") if pending_count >= self.min_email_to_process:
logger.info(f"已获取到 {imported} 个新邮箱,总可用邮箱数 {pending_count},确保注册进程运行")
if not self.registration_process or self.registration_process.poll() is not None: if not self.registration_process or self.registration_process.poll() is not None:
await self.start_registration_process() await self.start_registration_process()
pending_count = new_count # 更新计数器
if imported < 15: # 每次API应返回15个账号 if imported < 15: # 每次API应返回15个账号
logger.warning(f"获取到的邮箱少于预期 ({imported} < 15),可能没有更多邮箱可用") logger.warning(f"获取到的邮箱少于预期 ({imported} < 15),可能没有更多邮箱可用")
@@ -294,7 +298,10 @@ class AutoCursorService:
logger.info("注册进程已在运行中") logger.info("注册进程已在运行中")
return return
# 检查可用邮箱数量 # 启动前等待1秒确保数据库状态已更新
await asyncio.sleep(1)
# 再次检查可用邮箱数量,确保使用最新状态
pending_count = await self.count_pending_accounts() pending_count = await self.count_pending_accounts()
if pending_count < self.min_email_to_process: if pending_count < self.min_email_to_process:
logger.warning(f"可用邮箱数量不足 ({pending_count} < {self.min_email_to_process}),暂不启动注册进程") logger.warning(f"可用邮箱数量不足 ({pending_count} < {self.min_email_to_process}),暂不启动注册进程")
@@ -403,6 +410,9 @@ class AutoCursorService:
self.reg_enabled = current_status self.reg_enabled = current_status
logger.info(f"注册状态变化为: {'开启' if self.reg_enabled else '关闭'}") logger.info(f"注册状态变化为: {'开启' if self.reg_enabled else '关闭'}")
# 状态变化后等待2秒确保数据库状态稳定
await asyncio.sleep(2)
if self.reg_enabled: if self.reg_enabled:
# 开启注册时,先检查并获取邮箱 # 开启注册时,先检查并获取邮箱
await self.check_and_fetch_emails() await self.check_and_fetch_emails()
@@ -415,6 +425,9 @@ class AutoCursorService:
# 关闭注册时,停止注册进程 # 关闭注册时,停止注册进程
self.stop_registration_process() self.stop_registration_process()
# 等待一会,确保上一步操作完全完成
await asyncio.sleep(1)
# 2. 如果注册已开启,检查并获取邮箱 # 2. 如果注册已开启,检查并获取邮箱
if self.reg_enabled: if self.reg_enabled:
await self.check_and_fetch_emails() await self.check_and_fetch_emails()
@@ -430,8 +443,11 @@ class AutoCursorService:
if current_time - last_upload_time >= self.upload_interval: if current_time - last_upload_time >= self.upload_interval:
await self.upload_accounts() await self.upload_accounts()
last_upload_time = current_time last_upload_time = current_time
# 上传后等待,确保数据库状态更新
await asyncio.sleep(2)
# 4. 等待下一次检查 # 4. 等待下一次检查
logger.debug(f"等待 {self.check_interval} 秒后进行下一次检查")
for _ in range(self.check_interval): for _ in range(self.check_interval):
if not self.running: if not self.running:
break break

View File

@@ -39,11 +39,15 @@ class EmailManager:
"""批量获取未使用的邮箱账号""" """批量获取未使用的邮箱账号"""
logger.info(f"尝试获取 {num} 个未使用的邮箱账号") logger.info(f"尝试获取 {num} 个未使用的邮箱账号")
# 1. 先查询符合条件的账号ID列表 # 使用简单条件获取未使用的账号
select_query = """ select_query = """
SELECT id, email, password, client_id, refresh_token SELECT id, email, password, client_id, refresh_token
FROM email_accounts FROM email_accounts
WHERE in_use = 0 AND sold = 0 AND status = 'pending' WHERE in_use = 0 AND sold = 0 AND status = 'pending'
AND email NOT IN (
SELECT email FROM email_accounts
WHERE status = 'success' OR status = 'unavailable'
)
LIMIT %s LIMIT %s
""" """
accounts = await self.db.fetch_all(select_query, (num,)) accounts = await self.db.fetch_all(select_query, (num,))
@@ -125,6 +129,10 @@ class EmailManager:
SELECT COUNT(*) SELECT COUNT(*)
FROM email_accounts FROM email_accounts
WHERE status = 'pending' AND in_use = 0 AND sold = 0 WHERE status = 'pending' AND in_use = 0 AND sold = 0
AND email NOT IN (
SELECT email FROM email_accounts
WHERE status = 'success' OR status = 'unavailable'
)
""" """
result = await self.db.fetch_one(query) result = await self.db.fetch_one(query)
if result: if result: