feat: 添加守护进程模式和部署脚本

This commit is contained in:
2026-02-05 21:29:59 +08:00
parent 48644c662f
commit 79168dec7e
3 changed files with 562 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
## 功能概述
- **守护进程模式**持续监控数据库自动处理新数据默认10秒轮询
- **批量处理模式**10张图片一个请求多请求并发执行
- **内容审核处理**:自动识别审核失败图片,标记状态并记录原因
- **RESTful API 服务**:提供标签衍生的 HTTP 接口
@@ -49,7 +50,8 @@ ai_tagging_images/
├── promt/
│ └── qwen_tag_derive_prompt.py
├── database_config.py # 数据库连接和 DAO
├── image_tag_derive.py # 离线批量处理脚本
├── image_tag_derive.py # 标签衍生主程序(支持守护模式)
├── start_tag_derive.sh # 部署管理脚本
├── logger.py # 日志模块
├── retry_handler.py # 重试机制
├── tag_derive_api.py # FastAPI 服务
@@ -81,8 +83,21 @@ export DB_HOST=localhost
export DB_PASSWORD=your-password
```
### 3. 运行离线脚本
### 3. 运行标签衍生服务
**守护模式(推荐):**
```bash
# 持续监控数据库,自动处理新数据
python image_tag_derive.py --daemon
# 指定轮询间隔默认10秒
python image_tag_derive.py --daemon --interval 10
# 并发配置
python image_tag_derive.py --daemon --batch-size 50 --concurrency 3
```
**单次执行模式:**
```bash
# 处理全部待处理数据
python image_tag_derive.py
@@ -107,6 +122,8 @@ python image_tag_derive.py --id 16495 16496 16497
**命令行参数:**
| 参数 | 说明 |
|------|------|
| `--daemon` | 守护模式:持续监控数据库 |
| `--interval` | 轮询间隔默认10秒 |
| `--limit` | 限制处理数量(测试用) |
| `--start-id` | 起始ID断点续传 |
| `--end-id` | 结束ID |
@@ -114,7 +131,30 @@ python image_tag_derive.py --id 16495 16496 16497
| `--concurrency` | 并发请求数 |
| `--id` | 指定处理的ID列表 |
### 4. 启动 API 服务
### 4. 部署管理脚本
```bash
# 启动服务
./start_tag_derive.sh start
# 停止服务
./start_tag_derive.sh stop
# 强制停止
./start_tag_derive.sh force-stop
# 重启服务
./start_tag_derive.sh restart
# 查看状态
./start_tag_derive.sh status
# 查看日志
./start_tag_derive.sh logs
./start_tag_derive.sh logs-follow
```
### 5. 启动 API 服务
```bash
python tag_derive_api.py