fix: Prevent double-prefixing of S2A team names and refactor Telegram bot's thread pool usage for non-blocking execution.
This commit is contained in:
@@ -710,7 +710,7 @@ def s2a_create_account_from_oauth(
|
|||||||
full_email = name if "@" in name else ""
|
full_email = name if "@" in name else ""
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
payload["name"] = f"team-{name}"
|
payload["name"] = name if name.startswith("team-") else f"team-{name}"
|
||||||
if proxy_id is not None:
|
if proxy_id is not None:
|
||||||
payload["proxy_id"] = proxy_id
|
payload["proxy_id"] = proxy_id
|
||||||
|
|
||||||
@@ -790,8 +790,9 @@ def s2a_add_account(
|
|||||||
if token_info.get("email"):
|
if token_info.get("email"):
|
||||||
credentials["email"] = token_info.get("email")
|
credentials["email"] = token_info.get("email")
|
||||||
|
|
||||||
|
s2a_name = name if name.startswith("team-") else f"team-{name}"
|
||||||
payload = {
|
payload = {
|
||||||
"name": f"team-{name}",
|
"name": s2a_name,
|
||||||
"platform": "openai",
|
"platform": "openai",
|
||||||
"type": "oauth",
|
"type": "oauth",
|
||||||
"credentials": credentials,
|
"credentials": credentials,
|
||||||
|
|||||||
@@ -3985,18 +3985,16 @@ class ProvisionerBot:
|
|||||||
if worker_id in current_steps:
|
if worker_id in current_steps:
|
||||||
del current_steps[worker_id]
|
del current_steps[worker_id]
|
||||||
|
|
||||||
# 使用线程池并发执行
|
# 使用线程池并发执行 (通过 run_in_executor 避免阻塞 event loop)
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
|
||||||
futures = [executor.submit(worker_task, i) for i in range(workers)]
|
async_futures = [loop.run_in_executor(executor, worker_task, i) for i in range(workers)]
|
||||||
|
results_done = await asyncio.gather(*async_futures, return_exceptions=True)
|
||||||
# 等待所有任务完成
|
for r in results_done:
|
||||||
for future in concurrent.futures.as_completed(futures):
|
if isinstance(r, Exception):
|
||||||
try:
|
log.error(f"Worker 异常: {r}")
|
||||||
future.result()
|
|
||||||
except Exception as e:
|
|
||||||
log.error(f"Worker 异常: {e}")
|
|
||||||
|
|
||||||
# 检查是否被停止
|
# 检查是否被停止
|
||||||
stopped = False
|
stopped = False
|
||||||
|
|||||||
Reference in New Issue
Block a user