This commit is contained in:
huangzhenpc
2025-04-01 17:25:45 +08:00
parent 46ee69d2f8
commit 6d618d36ac

View File

@@ -252,7 +252,7 @@ class AutoCursorService:
if pending_count >= self.min_email_to_process and self.reg_enabled: 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: if not self.registration_process or self.registration_process.poll() is not None:
logger.info("有足够邮箱但注册进程未运行,启动注册进程") logger.info("有足够邮箱但注册进程未运行,启动注册进程")
self.start_registration_process() await self.start_registration_process()
return 0 return 0
# 需要获取新邮箱 # 需要获取新邮箱
@@ -274,7 +274,7 @@ class AutoCursorService:
if new_count >= self.min_email_to_process: if new_count >= self.min_email_to_process:
logger.info(f"已获取到 {imported} 个新邮箱,总可用邮箱数 {new_count},确保注册进程运行") logger.info(f"已获取到 {imported} 个新邮箱,总可用邮箱数 {new_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:
self.start_registration_process() await self.start_registration_process()
pending_count = new_count # 更新计数器 pending_count = new_count # 更新计数器
if imported < 15: # 每次API应返回15个账号 if imported < 15: # 每次API应返回15个账号
@@ -287,42 +287,36 @@ class AutoCursorService:
return total_imported return total_imported
def start_registration_process(self): async def start_registration_process(self):
"""启动注册进程""" """启动注册进程"""
if self.registration_process and self.registration_process.poll() is None: if self.registration_process and self.registration_process.poll() is None:
logger.info("注册进程已在运行中") logger.info("注册进程已在运行中")
return return
# 先异步检查可用邮箱数量 # 直接检查可用邮箱数量
async def check_and_start(): 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}),暂不启动注册进程") return
return
logger.info(f"{pending_count} 个可用邮箱,启动注册进程")
try:
# 使用subprocess启动main.py
if sys.platform.startswith("win"):
self.registration_process = subprocess.Popen(
["python", "main.py"],
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
)
else:
self.registration_process = subprocess.Popen(
["python3", "main.py"]
)
logger.info(f"注册进程已启动PID: {self.registration_process.pid}")
except Exception as e:
logger.error(f"启动注册进程时出错: {e}")
self.registration_process = None
# 创建临时事件循环来运行异步检查 logger.info(f"{pending_count} 个可用邮箱,启动注册进程")
loop = asyncio.new_event_loop() try:
loop.run_until_complete(check_and_start()) # 使用subprocess启动main.py
loop.close() if sys.platform.startswith("win"):
self.registration_process = subprocess.Popen(
["python", "main.py"],
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
)
else:
self.registration_process = subprocess.Popen(
["python3", "main.py"]
)
logger.info(f"注册进程已启动PID: {self.registration_process.pid}")
except Exception as e:
logger.error(f"启动注册进程时出错: {e}")
self.registration_process = None
def stop_registration_process(self): def stop_registration_process(self):
"""停止注册进程""" """停止注册进程"""
@@ -408,7 +402,7 @@ class AutoCursorService:
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.info(f"{pending_count} 个可用邮箱,启动注册进程") logger.info(f"{pending_count} 个可用邮箱,启动注册进程")
self.start_registration_process() await self.start_registration_process()
else: else:
# 关闭注册时,停止注册进程 # 关闭注册时,停止注册进程
self.stop_registration_process() self.stop_registration_process()
@@ -421,7 +415,7 @@ class AutoCursorService:
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.info(f"发现 {pending_count} 个未处理的邮箱,重新启动注册进程") logger.info(f"发现 {pending_count} 个未处理的邮箱,重新启动注册进程")
self.start_registration_process() await self.start_registration_process()
# 3. 定期上传账号 # 3. 定期上传账号
current_time = time.time() current_time = time.time()