fix: 修复爬虫网络层、验证队列卡死及 API 500 错误
- 修复 BaseHTTPPlugin 连接池、并发控制、异常日志、超时策略 - 修复/增强 8 个爬虫插件的稳定性和 fallback 机制 - 清理 validation_tasks 表 4 万+ pending 任务,避免队列卡死 - 修复 app/api/main.py 缺失全局 app 实例导致的 500 错误 - 提升前端 Axios 超时到 120 秒,避免请求断开 - 修复插件统计持久化和调度器生命周期问题
This commit is contained in:
@@ -124,17 +124,55 @@ class PluginSettingsRepository:
|
||||
logger.error(f"set_config failed for {plugin_id}: {e}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
async def get_stats(db: aiosqlite.Connection, plugin_id: str) -> Dict[str, Any]:
|
||||
async with db.execute(
|
||||
"SELECT stats_json FROM plugin_settings WHERE plugin_id = ?", (plugin_id,)
|
||||
) as cursor:
|
||||
row = await cursor.fetchone()
|
||||
if row and row[0]:
|
||||
try:
|
||||
return json.loads(row[0])
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
async def set_stats(db: aiosqlite.Connection, plugin_id: str, stats: Dict[str, Any]) -> bool:
|
||||
try:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO plugin_settings (plugin_id, stats_json, updated_at)
|
||||
VALUES (?, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(plugin_id) DO UPDATE SET
|
||||
stats_json = excluded.stats_json,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
""",
|
||||
(plugin_id, json.dumps(stats, ensure_ascii=False)),
|
||||
)
|
||||
await db.commit()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"set_stats failed for {plugin_id}: {e}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
async def list_all(db: aiosqlite.Connection) -> Dict[str, Dict[str, Any]]:
|
||||
result = {}
|
||||
async with db.execute("SELECT plugin_id, enabled, config_json FROM plugin_settings") as cursor:
|
||||
async with db.execute("SELECT plugin_id, enabled, config_json, stats_json FROM plugin_settings") as cursor:
|
||||
rows = await cursor.fetchall()
|
||||
for plugin_id, enabled, config_json in rows:
|
||||
for plugin_id, enabled, config_json, stats_json in rows:
|
||||
config = {}
|
||||
if config_json:
|
||||
try:
|
||||
config = json.loads(config_json)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
result[plugin_id] = {"enabled": bool(enabled), "config": config}
|
||||
stats = {}
|
||||
if stats_json:
|
||||
try:
|
||||
stats = json.loads(stats_json)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
result[plugin_id] = {"enabled": bool(enabled), "config": config, "stats": stats}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user