This commit is contained in:
huangzhenpc
2025-04-01 17:58:08 +08:00
parent 058f172aba
commit 6dad187156
4 changed files with 462 additions and 10 deletions

View File

@@ -44,6 +44,10 @@ class EmailManager:
SELECT id, email, password, client_id, refresh_token
FROM email_accounts
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
"""
accounts = await self.db.fetch_all(select_query, (num,))
@@ -55,7 +59,7 @@ class EmailManager:
# 2. 提取账号ID列表
account_ids = [account['id'] for account in accounts]
# 3. 更新这些账号的状态
# 3. 更新这些账号的状态,设置注册开始时间戳,避免其他进程获取
if account_ids:
placeholders = ', '.join(['%s' for _ in account_ids])
update_query = f"""
@@ -64,6 +68,9 @@ class EmailManager:
WHERE id IN ({placeholders})
"""
await self.db.execute(update_query, tuple(account_ids))
# 记录被锁定的账号信息
logger.info(f"已锁定 {len(account_ids)} 个账号用于注册: {account_ids}")
# 4. 返回账号数据
logger.debug(f"实际获取到 {len(accounts)} 个账号")
@@ -116,6 +123,22 @@ class EmailManager:
'''
await self.db.execute(query, (account_id,))
async def count_pending_accounts(self) -> int:
"""统计可用的pending状态账号数量"""
query = """
SELECT COUNT(*)
FROM email_accounts
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)
if result:
return result.get("COUNT(*)", 0)
return 0
async def _get_access_token(self, client_id: str, refresh_token: str) -> str:
"""获取微软 access token"""
logger.debug(f"开始获取 access token - client_id: {client_id}")