优化注册

This commit is contained in:
huangzhenpc
2025-05-07 09:21:38 +08:00
parent 4bea0d3aa8
commit 427baca00a
2 changed files with 68 additions and 55 deletions

View File

@@ -57,16 +57,16 @@ class AutoCursorService:
auto_service_config = getattr(self.config, "auto_service_config", None)
if auto_service_config:
self.check_interval = getattr(auto_service_config, "check_interval", 60)
self.upload_interval = getattr(auto_service_config, "upload_interval", 300)
self.upload_interval = getattr(auto_service_config, "upload_interval", 60)
self.email_check_threshold = getattr(auto_service_config, "email_check_threshold", 30)
self.email_fetch_count = getattr(auto_service_config, "email_fetch_count", 2)
else:
self.check_interval = 60 # 检查API状态的间隔
self.upload_interval = 300 # 上传账号间隔(秒)
self.upload_interval = 60 # 上传账号间隔(秒)
self.email_check_threshold = 30 # 当可用邮箱少于这个数时获取新邮箱
self.email_fetch_count = 2 # 获取邮箱的次数每次15个
# 处理邮箱的最小数量阈值,只要有这么多邮箱就会立即处理
# 处理邮箱的最小数量阈值,只要有1个邮箱就会立即处理
self.min_email_to_process = 1
# 运行状态控制
@@ -274,50 +274,50 @@ class AutoCursorService:
pending_count = await self.count_pending_accounts()
logger.info(f"当前可用邮箱数量: {pending_count}")
if pending_count >= self.email_check_threshold:
logger.info(f"可用邮箱数量充足 ({pending_count} >= {self.email_check_threshold})")
# 确保注册进程已启动
if pending_count >= self.min_email_to_process and self.reg_enabled:
if not self.registration_process or self.registration_process.poll() is not None:
logger.info("有足够邮箱但注册进程未运行,启动注册进程")
await self.start_registration_process()
return 0
# 如果有可用邮箱并且注册已开启,立即确保注册进程在运行
if pending_count > 0 and self.reg_enabled:
if not self.registration_process or self.registration_process.poll() is not None:
logger.info(f"{pending_count} 个可用邮箱但注册进程未运行,立即启动注册进程")
await self.start_registration_process()
# 如果成功启动注册进程且邮箱数量足够,可以不再获取新邮箱
if pending_count >= self.email_check_threshold:
return 0
# 需要获取新邮箱
logger.info(f"可用邮箱不足 ({pending_count} < {self.email_check_threshold}),准备获取新邮箱")
total_imported = 0
# 只有当邮箱数量不足时才获取新邮箱
if pending_count < self.email_check_threshold:
logger.info(f"可用邮箱不足 ({pending_count} < {self.email_check_threshold}),准备获取新邮箱")
total_imported = 0
for i in range(self.email_fetch_count):
accounts = await self.fetch_email_accounts()
if not accounts:
logger.warning(f"{i+1} 次获取邮箱失败或无可用邮箱")
break
for i in range(self.email_fetch_count):
accounts = await self.fetch_email_accounts()
if not accounts:
logger.warning(f"{i+1} 次获取邮箱失败或无可用邮箱")
break
imported = await self.import_email_accounts(accounts)
total_imported += imported
imported = await self.import_email_accounts(accounts)
total_imported += imported
# 导入后等待一秒,确保数据库状态完全更新
logger.debug("等待数据库状态更新...")
await asyncio.sleep(2)
# 导入后等待一秒,确保数据库状态完全更新
logger.debug("等待数据库状态更新...")
await asyncio.sleep(2)
# 每次获取到新邮箱并成功导入后,立即确保注册进程在运行
if imported > 0 and self.reg_enabled:
# 重新查询一次确保数据是最新的
pending_count = await self.count_pending_accounts()
if pending_count >= self.min_email_to_process:
logger.info(f"已获取到 {imported} 个新邮箱,总可用邮箱数 {pending_count},确保注册进程运行")
# 每次获取到新邮箱并成功导入后,立即启动注册进程
if imported > 0 and self.reg_enabled:
logger.info(f"已获取到 {imported} 个新邮箱,立即启动注册进程")
if not self.registration_process or self.registration_process.poll() is not None:
await self.start_registration_process()
if imported < 15: # 每次API应返回15个账号
logger.warning(f"获取到的邮箱少于预期 ({imported} < 15),可能没有更多邮箱可用")
break
if imported < 15: # 每次API应返回15个账号
logger.warning(f"获取到的邮箱少于预期 ({imported} < 15),可能没有更多邮箱可用")
break
if i < self.email_fetch_count - 1:
# 在多次请求之间添加延迟
await asyncio.sleep(2)
if i < self.email_fetch_count - 1:
# 在多次请求之间添加延迟
await asyncio.sleep(2)
return total_imported
return total_imported
return 0
async def start_registration_process(self):
"""启动注册进程"""
@@ -331,8 +331,8 @@ class AutoCursorService:
# 再次检查可用邮箱数量,确保使用最新状态
pending_count = await self.count_pending_accounts()
if pending_count < self.min_email_to_process:
logger.warning(f"可用邮箱数量不足 ({pending_count} < {self.min_email_to_process}),暂不启动注册进程")
if pending_count < 1:
logger.warning(f"没有可用邮箱,暂不启动注册进程")
return
logger.info(f"{pending_count} 个可用邮箱,启动注册进程")
@@ -442,13 +442,16 @@ class AutoCursorService:
await asyncio.sleep(2)
if self.reg_enabled:
# 开启注册时,先检查并获取邮箱
await self.check_and_fetch_emails()
# 检查是否有可用邮箱,有则启动注册进程
# 开启注册时,先检查邮箱数量
pending_count = await self.count_pending_accounts()
if pending_count >= self.min_email_to_process:
logger.info(f"{pending_count}可用邮箱,启动注册进程")
if pending_count > 0:
# 有可用邮箱,立即启动注册进程
logger.info(f"注册开启,有 {pending_count} 个可用邮箱,立即启动注册进程")
await self.start_registration_process()
else:
# 没有邮箱,立即获取
logger.info("注册开启,但没有可用邮箱,立即获取新邮箱")
await self.check_and_fetch_emails()
else:
# 关闭注册时,停止注册进程
self.stop_registration_process()
@@ -456,15 +459,25 @@ class AutoCursorService:
# 等待一会,确保上一步操作完全完成
await asyncio.sleep(1)
# 2. 如果注册已开启,检查并获取邮箱
# 2. 如果注册已开启,检查邮箱情况并确保注册进程运行
if self.reg_enabled:
await self.check_and_fetch_emails()
# 确保注册进程正在运行
# 检查注册进程是否在运行
if not self.registration_process or self.registration_process.poll() is not None:
# 如果没有运行,检查是否有可用邮箱
pending_count = await self.count_pending_accounts()
if pending_count >= self.min_email_to_process:
logger.info(f"发现 {pending_count} 个未处理的邮箱,重新启动注册进程")
if pending_count > 0:
# 有邮箱,立即启动注册进程
logger.info(f"{pending_count} 个未处理的邮箱,立即启动注册进程")
await self.start_registration_process()
else:
# 没有可用邮箱,获取新邮箱
logger.info("没有可用邮箱,获取新邮箱")
await self.check_and_fetch_emails()
else:
# 注册进程已在运行,仍然检查邮箱数量,确保有足够邮箱
pending_count = await self.count_pending_accounts()
if pending_count < self.email_check_threshold:
await self.check_and_fetch_emails()
# 3. 定期上传账号
current_time = time.time()

View File

@@ -38,7 +38,7 @@ proxy:
batch_size: 100
check_interval: 300
# API专用代理可选
api_proxy: "http://1ddbeae0f7a67106fd58:f72e512b10893a1d@gw.dataimpulse.com:823"
api_proxy: "http://c44f8c35c8455936c137:78842e9932e456b8@gw.dataimpulse.com:823"
# 注册配置
register:
@@ -59,7 +59,7 @@ auto_service:
captcha:
provider: "capsolver" # 可选值: "capsolver" 或 "yescaptcha"
capsolver:
api_key: "CAP-36D01B0995C7C8705DF68ACCFE4E2004FE182DDA72AC5A80F25F1E3B601C31F0"
api_key: "CAP-BCCA3C15FCB8087683879B9A841C161A24F7DBB6440C6363ADF3D2451986DF43"
website_url: "https://authenticator.cursor.sh"
website_key: "0x4AAAAAAAMNIvC45A4Wjjln"
yescaptcha: