Files
huike-back/docs/integration_cutover.md
T
weli 44c320d8fa chore add core rust project files and diesel migrations
Track required workspace crates, scripts, and historical diesel migrations so the repository contains the complete runnable backend baseline.

Made-with: Cursor
2026-04-23 17:20:01 +08:00

65 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 联调与切流(htyts / htyproc
## 环境变量
### htyts(任务 API
`htyts::config` 一致,典型项包括:`TS_DATABASE_URL`、Redis`htycommons::redis_util` 所读变量)、`TS_PORT``task_server.zombie_min`(或等价)、JWT/密钥类变量与现有 `htyws`/`htykc` 对齐。课程调度:`TS_SUDOER_TOKEN``TS_DOMAIN``HTYKC_URL` 等。
### htyproc(执行器)
| 变量 | 说明 |
|------|------|
| `TS_URL` | 任务服务基址(含协议与端口),如 `http://127.0.0.1:8080` |
| `TS_DOMAIN` | `HtyHost` 语义,与现网域名一致 |
| `NGX_URL` | OpenResty/Nginx 基址,用于 `combine` / `convert` 等 |
| `PROC_SUDOER_TOKEN` | 调 TS 与 Ngx 的 sudoer JWT(与 Java proc 一致) |
| `PROC_PORT` | 控制面 HTTP 端口,默认 `8081` |
| `WAIT_SEC` / `task_server.wait_sec` | 轮询间隔秒数,默认 `5` |
| `MAX_PROCESSING_TASKS` | 并发执行上限,默认 `20` |
| Redis | 与 TS 相同实例;`htycommons::redis_util::get_redis_url()` |
## Nginx 示例
将原指向 Java `task_server` / `proc_server``location` 改为 Rust 进程 upstream(端口按部署调整):
```nginx
upstream htyts_backend {
server 127.0.0.1:8080;
}
upstream htyproc_backend {
server 127.0.0.1:8081;
}
location /api/v1/ts/ {
proxy_pass http://htyts_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api/v1/proc/ {
proxy_pass http://htyproc_backend;
proxy_set_header Host $host;
}
```
切流前在**并行端口**上跑 `htyts`/`htyproc`,用 curl 或 `htymusic`/`htyadmin` 指向测试域名验证后再改 `proxy_pass`
## 联调要点(htymusic / htyadmin
- 创建/更新任务、`one_pending_task` 拉取、任务状态回写与 Redis payload 一致。
- 课程通知:`/api/v1/ts/kc/*` 启停与状态与运维脚本一致。
- proc`GET /api/v1/proc/start|stop|status` 行为与 Java 一致后再切换 upstream。`status` 载荷中的 `status` 字段与 Java `ProcessorHelper.Status` 一致:`PENDING` / `RUNNING` / `ABORT` / `ERROR`
## 监控与下线 Java 条件建议
- 指标:`one_zombie_task` 数量、任务 `FAILED` 比例、proc 日志中 `update_task` 失败率、Redis `TS_*` 键与 DB 行一致性抽检。
- 条件:在目标环境**至少一个完整业务周期**内无回归;TS/proc 错误率与 Java 基线可比或更好;回滚方案(保留 Java 二进制与旧 upstream 块)已验证。
## htyts 本地 E2EDocker + cargo test
- Compose`huiwing/docker-compose.ts-e2e.yml`Postgres 14、Redis 7;端口 `5436` / `6390`,避免与 AuthCore `docker-compose.test.yml``5433` / `6380` 冲突)。
- 建表:`huiwing/htyts_models/migrations/`,本地/CI 用 `diesel migration run`(与 `htyuc_models` 相同流程)。
- 一键脚本:`huiwing/scripts/run-ts-e2e.sh``up --wait`、清空 `dbtask` 与 Redis、`POOL_SIZE`/`JWT_KEY`/DB URL 等环境变量后执行 `cargo test -p htyts --test ts_e2e_http`
- `HtySudoerToken` 校验依赖 Redis 中 `HW_T_{token_id}` 与 JWT 一致;测试内会写入与 AuthCore `verify_jwt` 相同的约定。