05635b76b9
状态: - 9 个 sync task(stock_basic / kline_daily / kline_index / kline_5min / moneyflow / industry_sector / sector_features / share_snapshot / market_regime) - 数据源:baostock + mairui + 雪球(pysnowball) + 新浪(4 个) - 项目级约束:永远不用 akshare(已落实) - kline_5min 改用 DB 快照统一全量/增量逻辑 - 零后端 Chrome 扩展 xueqiu_sync(独立项目)
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""数据源管理:列出 / 测试 / 启用状态查询。"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from app.core.datasource.base import registry as ds_registry
|
|
from app.core.datasource.registry import (
|
|
get_health_status,
|
|
is_source_ready,
|
|
run_health_check,
|
|
)
|
|
|
|
router = APIRouter(prefix="/api/datasources", tags=["datasources"])
|
|
|
|
|
|
@router.get("")
|
|
def list_datasources():
|
|
"""列出所有注册数据源 + 状态。"""
|
|
items = []
|
|
for src in ds_registry.all():
|
|
ok, reason = is_source_ready(src.key)
|
|
health = next((h for h in get_health_status() if h["key"] == src.key), None)
|
|
items.append({
|
|
"key": src.key,
|
|
"name": src.name,
|
|
"provides": src.provides,
|
|
"requiresCredential": src.requires_credential,
|
|
"credentialKey": src.credential_key,
|
|
"ready": ok,
|
|
"readyReason": reason,
|
|
"health": health,
|
|
})
|
|
return {"datasources": items}
|
|
|
|
|
|
@router.post("/test/{source_key}")
|
|
def test_one(source_key: str):
|
|
if ds_registry.get(source_key) is None:
|
|
raise HTTPException(404, f"数据源 {source_key} 未注册")
|
|
result = run_health_check(source_key)
|
|
return {"result": result[0] if result else None}
|
|
|
|
|
|
@router.post("/test-all")
|
|
def test_all():
|
|
results = run_health_check()
|
|
return {"results": results}
|