fix: 删除数据集时 RAGFlow 报错也视为成功

RAGFlow 删除(权限不足/数据集不存在等)失败时吞掉异常、记 warning,
继续清理本地 user_datasets 关联记录并向用户返回成功。
顺带在 README 补充生产发布流程。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
朱潮 2026-06-21 10:03:56 +08:00
parent 86bf8285e5
commit 82dad33a95
2 changed files with 55 additions and 5 deletions

View File

@ -58,6 +58,48 @@ docker-compose up -d
---
## 🚀 生产发布流程linggan 服务器)
代码推送到 `gitea` 仓库的 `bot_manager` 分支后,再到生产服务器拉代码、重建容器。
### 1. 本地提交并推送
```bash
# 在 qwen-agent 目录
git add <files>
git commit -m "<message>"
git push gitea bot_manager
```
> 远端 `gitea` 指向 `ssh://gitea@git.aitravelmaster.com:2006/zhuchaowe/qwen_agent.git`,是团队主仓库;`origin` 是 GitHub fork发布时不用。
### 2. 服务器拉代码并重启
```bash
# ssh 到 lingganfish shell 中ssh-connect linggan
ssh ubuntu@175.27.142.79
# 拉最新代码(.git 是 root 所有,需要 sudo当前用户已配 NOPASSWD
cd /opt/1panel/www/sites/qwen_agent
sudo git pull origin bot_manager
# 重建并重启 qwen-agent 容器compose 文件用 docker-compose-with-pgsql.yml
docker compose -f docker-compose-with-pgsql.yml build qwen-agent
docker compose -f docker-compose-with-pgsql.yml up -d qwen-agent
# 验证(容器有 40s healthcheck start_period刚启动可能要等一会才 healthy
docker ps --filter name=qwen-agent-api
curl -s http://localhost:8001/api/health
```
### 注意
- 只 build / up `qwen-agent` 服务,**不要动 `postgres`**(带数据卷)
- 用 `up -d` 而不是 `restart`,才能让新 build 的镜像生效
- `Dockerfile.modelscope` 较重build 通常需要几分钟
---
## 📖 使用指南
# Catalog Agent API 文档

View File

@ -289,6 +289,9 @@ class KnowledgeBaseService:
"""
删除数据集
RAGFlow 删除失败权限不足数据集已不存在等时不阻断流程
仍清理本地关联记录并向用户返回成功
Args:
dataset_id: 数据集 ID
user_id: 用户 ID可选用于权限验证
@ -305,11 +308,16 @@ class KnowledgeBaseService:
logger.warning(f"User {user_id} has no access to dataset {dataset_id}")
return False
# 从 RAGFlow 删除
result = await self.repository.delete_datasets([dataset_id])
# 从 RAGFlow 删除(失败不阻断,吞掉异常继续清理本地记录)
try:
await self.repository.delete_datasets([dataset_id])
except Exception as e:
logger.warning(
f"RAGFlow delete dataset {dataset_id} failed (will still unlink locally): {e}"
)
# 从本地数据库删除关联记录
if result and user_id:
# 从本地数据库删除关联记录(无论 RAGFlow 是否成功都执行)
if user_id:
pool = get_db_pool_manager().pool
async with pool.connection() as conn:
async with conn.cursor() as cursor:
@ -320,7 +328,7 @@ class KnowledgeBaseService:
await conn.commit()
logger.info(f"Dataset {dataset_id} unlinked from user {user_id}")
return result
return True
# ============== 文件管理 ==============