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:
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
|
||||
import main
|
||||
|
||||
from .config import SettingsStore
|
||||
from .connectors import build_client, build_storage, build_store, close_quietly
|
||||
|
||||
|
||||
def run(settings_path: Path, output_dir: Path, dry_run: bool) -> int:
|
||||
settings = SettingsStore(settings_path).get()
|
||||
print(f"storage_mode={settings.storage_mode}")
|
||||
print(f"database_mode={'none' if dry_run else settings.database_mode}")
|
||||
client = build_client(settings)
|
||||
storage = build_storage(settings, client)
|
||||
try:
|
||||
source = main.StorageSource(storage, settings.source_root, settings.cell_data_directories)
|
||||
store = None if dry_run else build_store(settings, client)
|
||||
history = None
|
||||
if store is not None and settings.history_enabled:
|
||||
history = main.StorageHistoryStore(storage, settings.history_root)
|
||||
main.process(source, output_dir, settings.lookback_days, store=store, history=history)
|
||||
finally:
|
||||
close_quietly(storage)
|
||||
return 0
|
||||
|
||||
|
||||
def entry(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description="Run one InterferenceETL pass with the saved app settings")
|
||||
parser.add_argument("--settings", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
return run(args.settings, args.output, args.dry_run)
|
||||
except main.ProcessingError as exc:
|
||||
print(f"error={exc}", file=sys.stderr, flush=True)
|
||||
return 1
|
||||
except Exception as exc:
|
||||
traceback.print_exc()
|
||||
print(f"error={type(exc).__name__}: {exc}", file=sys.stderr, flush=True)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(entry())
|
||||
Reference in New Issue
Block a user