feat: 新增Metrix托管应用模式,含管理界面与容器内定时运行

- etl_app:FastAPI + NiceGUI 管理页(概览、运行记录、设置),仅 Metrix 管理员可访问,中英文与日夜间
- 设置页可配定时频率(间隔/Cron)、超时、Metrix 接口、FTP/SFTP 直连、MySQL 直连、目录与保留策略,密码只写不回显
- APScheduler 在同一容器内定时,每次运行是容器内子进程,单实例互斥、超时终止,运行记录存 SQLite、日志落盘
- main.py 抽出文件存储与数据库写入接口,新增 FTP/SFTP/MySQL 实现,脚本模式 CLI 不变
- deploy/Dockerfile、requirements-app.txt、scripts/package_metrix.py 生成应用包,README 补充说明
- 新增 tests/test_app.py,覆盖设置、运行记录、执行器、调度、身份、接口与各连接器
This commit is contained in:
2026-11-06 16:53:36 +08:00
parent ba2d3b2490
commit 96dd78baca
21 changed files with 3806 additions and 137 deletions
+31
View File
@@ -73,6 +73,37 @@ python main.py --source-dir C:\path\to\mock-or-exported-tree --output-dir output
Use `--window 2026073110001100` to select the natural 15-minute group containing that source start time. Without it, the newest observed source start time determines the group. Incomplete groups wait and never fall back.
## Metrix hosted app
The app mode runs InterferenceETL as one long-lived container in Metrix App Hosting. A FastAPI + NiceGUI admin page at `/admin` (Metrix account, admin role only) edits every setting, shows the live log and keeps the run history. The schedule runs inside the same container with APScheduler (fixed interval in minutes or a 5-field cron expression, timezone `Asia/Shanghai`). Each run is a child Python process inside that container, so no extra containers are started; one run at a time, with a per-run timeout.
Settings live on the app data volume and are edited only through the admin page:
- Source storage: Metrix storage API, or direct FTP / SFTP (host, port, account, FTP encoding and passive mode).
- Database: Metrix database connection API, or direct MySQL (host, port, account). Database and table names are configurable.
- Metrix API address and token are required only when either side uses the Metrix API.
- Source root, history CSV directory (optional), CellData directories, lookback days and retention.
Passwords and tokens are written to `/data/settings.json` (mode 0600) and never returned to the browser; a blank field keeps the saved value. Run records are in `/data/runs.db`, run logs in `/data/logs/`, local outputs in `/data/output/` (newest 48 kept by default).
Build the app bundle on a machine with docker, then upload it in App Hosting:
```powershell
python scripts\package_metrix.py
```
The bundle `dist/metrix/interference-etl-<version>.zip` contains `metrix-app.json`, `icon.svg` and `image.tar` built from `deploy/Dockerfile`. `--pip-index` and `--python-image` override the package index and base image. The schedule starts paused; enable it from the overview page after the connection test passes.
For local development of the app:
```powershell
python -m pip install -r requirements-app.txt
$env:METRIX_APP_DATA_DIR = "Temp\appdata"; $env:ETL_DEV_ADMIN = "1"; $env:PORT = "18090"
python -m etl_app.server
```
`ETL_DEV_ADMIN=1` grants admin access only when no Metrix proxy token is configured.
## Metrix Script Management
The target server is offline. Build the dependency image locally, then generate a self-contained Script Management upload ZIP: