pipeline-bidding/wwwroot/api/bid_probe.dspy

37 lines
1.4 KiB
Plaintext

# bid_probe.dspy — 投标产线服务内探针(诊断用)
# GET/POST: action=status | reconcile
# status → 模块装载状态 + poller 心跳 + 活跃投标项目数
# reconcile → 在服务进程内跑一轮全量对账,返回动作明细
import json
action = (params_kw or {}).get('action', 'status')
dbname = get_module_dbname('pipeline-bidding')
try:
import pipeline_bidding
from pipeline_bidding import bid_flow
loaded = True
ver = getattr(pipeline_bidding, '__version__', '?')
except Exception as e:
loaded = False
ver = str(e)[:100]
if action == 'reconcile':
try:
res = await bid_flow.reconcile_all()
return json.dumps({"success": True, "projects": res}, ensure_ascii=False, default=str)
except Exception as e:
return json.dumps({"success": False, "error": str(e)[:300]}, ensure_ascii=False)
out = {"loaded": loaded, "version": ver,
"poller_state": getattr(bid_flow, 'POLLER_STATE', None) if loaded else None}
if loaded:
async with DBPools().sqlorContext(dbname) as sor:
recs = await sor.sqlExe(
"SELECT COUNT(*) AS c FROM sd_projects WHERE pipeline_id='bidding_general' "
"AND status NOT IN ('paused','archived','completed','cancelled')", {})
await sor.sqlExe("COMMIT", {})
out["active_projects"] = getattr(recs[0], 'c', 0) if recs else 0
return json.dumps(out, ensure_ascii=False, default=str)