Przeglądaj źródła

推理时间加长

袁威 2 tygodni temu
rodzic
commit
adc3b329db
1 zmienionych plików z 11 dodań i 3 usunięć
  1. 11 3
      app/api/auto_import.py

+ 11 - 3
app/api/auto_import.py

@@ -12,6 +12,14 @@ from app.utils.scheme import CardType, IMAGE_TYPE_TO_SCORE_TYPE
 logger = get_logger(__name__)
 router = APIRouter()
 
+IMPORT_REQUEST_TIMEOUT = aiohttp.ClientTimeout(
+    total=600,
+    connect=10,
+    sock_connect=10,
+    sock_read=480,
+)
+
+
 # --- 内部辅助函数 ---
 async def call_api_with_bytes(
         session: aiohttp.ClientSession,
@@ -202,10 +210,9 @@ async def auto_import_script_api(
 
     is_reflect_str = "true" if is_reflect_card else "false"
 
-    timeout = aiohttp.ClientTimeout(total=180, connect=5, sock_connect=5, sock_read=120)
     connector = aiohttp.TCPConnector(limit=20, force_close=True)
 
-    async with aiohttp.ClientSession(timeout=timeout, connector=connector) as session:
+    async with aiohttp.ClientSession(timeout=IMPORT_REQUEST_TIMEOUT, connector=connector) as session:
         try:
             main_bytes_data = {k: (await v.read(), v.filename) for k, v in valid_main_files.items()}
             gray_bytes_data = {k: (await v.read(), v.filename) for k, v in valid_gray_files.items()}
@@ -311,7 +318,8 @@ async def auto_import_url_script_api(
 
     is_reflect_str = "true" if is_reflect_card else "false"
 
-    async with aiohttp.ClientSession() as session:
+    connector = aiohttp.TCPConnector(limit=20, force_close=True)
+    async with aiohttp.ClientSession(timeout=IMPORT_REQUEST_TIMEOUT, connector=connector) as session:
         try:
             logger.info(f"--- 开始URL自动导入任务: {card_name} ---")