refactor: 平台改为代码内置 provider 架构,一次性迁移现有数据 - 新增 app/providers:BalanceProvider 基类 + DeepSeek 适配器 + 注册表 - platforms 表去除 method/url/headers/body/balance_path,新增 provider_id - 现有数据库已一次性迁移(备份 data/monitor.db.bak-v1),不保留迁移工具 - 平台 UI 改为选择内置提供方;fetcher/monitor 走 provider 构建请求与解析 - 表达式引擎(运算符/函数)随架构保留,供 provider 内部使用 - 测试更新至 provider 模式,共 92 个
This commit is contained in:
+19
-8
@@ -18,6 +18,7 @@ from app import db
|
||||
from app.alert import evaluate, notify_disabled
|
||||
from app.config import Config
|
||||
from app.fetcher import fetch_balance
|
||||
from app.providers import get_provider
|
||||
|
||||
logger = logging.getLogger("monitor.scheduler")
|
||||
|
||||
@@ -28,17 +29,15 @@ _ACCOUNT_FIELDS = [
|
||||
"last_check_at", "note",
|
||||
]
|
||||
_PLATFORM_FIELDS = [
|
||||
"platform_id", "platform_name", "currency", "icon", "method", "url",
|
||||
"headers", "body", "balance_path", "interval_seconds",
|
||||
"retry_count", "timeout_seconds", "platform_enabled", "note",
|
||||
"platform_id", "provider_id", "platform_name", "currency", "icon",
|
||||
"interval_seconds", "retry_count", "timeout_seconds", "platform_enabled", "note",
|
||||
]
|
||||
|
||||
_ACCOUNT_SQL = """
|
||||
SELECT a.*,
|
||||
p.name AS platform_name, p.currency, p.icon, p.method, p.url,
|
||||
p.headers, p.body, p.balance_path, p.interval_seconds,
|
||||
p.retry_count, p.timeout_seconds, p.enabled AS platform_enabled,
|
||||
p.note AS platform_note
|
||||
p.provider_id, p.name AS platform_name, p.currency, p.icon,
|
||||
p.interval_seconds, p.retry_count, p.timeout_seconds,
|
||||
p.enabled AS platform_enabled, p.note AS platform_note
|
||||
FROM accounts a JOIN platforms p ON p.id = a.platform_id
|
||||
"""
|
||||
|
||||
@@ -138,13 +137,25 @@ class Monitor:
|
||||
def _check_one(self, row: dict) -> None:
|
||||
cfg = self.cfg
|
||||
account, platform = _split(row)
|
||||
provider = get_provider(platform["provider_id"])
|
||||
if provider is None:
|
||||
logger.warning("平台 %s 的 provider 不存在: %r", platform["name"], platform["provider_id"])
|
||||
with db.get_conn() as conn:
|
||||
conn.execute(
|
||||
"UPDATE accounts SET last_status='error', last_error=?, "
|
||||
"last_check_at=datetime('now','localtime') WHERE id=?",
|
||||
(f"provider 不存在: {platform['provider_id']}", account["id"]),
|
||||
)
|
||||
with self._lock:
|
||||
self._next_check[account["id"]] = time.time() + _account_interval(platform, cfg)
|
||||
return
|
||||
retry = platform.get("retry_count")
|
||||
if retry is None:
|
||||
retry = cfg.retry_count
|
||||
timeout = platform.get("timeout_seconds")
|
||||
if timeout is None:
|
||||
timeout = cfg.timeout_seconds
|
||||
result = fetch_balance(platform, account["api_key"], int(retry), int(timeout))
|
||||
result = fetch_balance(provider, account["api_key"], int(retry), int(timeout))
|
||||
|
||||
with db.get_conn() as conn:
|
||||
if result.ok:
|
||||
|
||||
Reference in New Issue
Block a user