This commit is contained in:
2026-03-06 12:44:57 +08:00
parent fa61b11b02
commit 006b035de4
132 changed files with 1361 additions and 17400 deletions

View File

@@ -7,11 +7,16 @@ import asyncio
import logging
from typing import Optional, Dict
from datetime import datetime
from .websocket_client import QingjianAPIClient
from .websocket_client_v2 import QingjianAPIClient
from db.task_db.task_model import get_task_manager, TaskStatus, TaskPriority
logger = logging.getLogger(__name__)
# 配置常量
TIMEOUT_CHECK_INTERVAL_SEC = 300 # 超时检查间隔5分钟
ERROR_RETRY_DELAY_SEC = 60 # 错误后重试延迟1分钟
QUEUE_POLL_INTERVAL_SEC = 1 # 队列轮询间隔(秒)
class TaskScheduler:
"""任务调度器"""
@@ -54,14 +59,14 @@ class TaskScheduler:
# 通知天网任务超时
await self._notify_tianwang(task['task_id'], 'timeout')
# 每 5 分钟检查一次
await asyncio.sleep(300)
# 每隔固定时间检查一次
await asyncio.sleep(TIMEOUT_CHECK_INTERVAL_SEC)
except asyncio.CancelledError:
break
except Exception as e:
logger.error(f"超时检查失败:{e}")
await asyncio.sleep(60)
await asyncio.sleep(ERROR_RETRY_DELAY_SEC)
async def _process_task_queue(self):
"""处理任务队列"""
@@ -69,8 +74,8 @@ class TaskScheduler:
while self.running:
try:
# 这里实际应该从队列获取任务
# 简化处理:每秒检查一次待触发任务
await asyncio.sleep(1)
# 简化处理:定期检查待触发任务
await asyncio.sleep(QUEUE_POLL_INTERVAL_SEC)
except Exception as e:
logger.error(f"任务队列处理失败:{e}")