fix: add try/except to capture pipeline visual error message
This commit is contained in:
@@ -906,63 +906,57 @@ def api_xau_brief():
|
|||||||
@app.route("/api/pipeline/visual/<asset>", methods=["GET"])
|
@app.route("/api/pipeline/visual/<asset>", methods=["GET"])
|
||||||
def pipeline_visual_asset(asset):
|
def pipeline_visual_asset(asset):
|
||||||
"""Pipeline visual específico por ativo (USD/XAU simulado via DB)."""
|
"""Pipeline visual específico por ativo (USD/XAU simulado via DB)."""
|
||||||
conn = _db_conn(DB_PATH)
|
try:
|
||||||
conn.row_factory = sqlite3.Row
|
conn = _db_conn(DB_PATH)
|
||||||
c = conn.cursor()
|
conn.row_factory = sqlite3.Row
|
||||||
|
c = conn.cursor()
|
||||||
|
|
||||||
last = c.execute("SELECT * FROM pipeline_runs ORDER BY started_at DESC LIMIT 1").fetchone()
|
last = c.execute("SELECT * FROM pipeline_runs ORDER BY started_at DESC LIMIT 1").fetchone()
|
||||||
last_5 = c.execute("SELECT * FROM pipeline_runs ORDER BY started_at DESC LIMIT 5").fetchall()
|
last_5 = c.execute("SELECT * FROM pipeline_runs ORDER BY started_at DESC LIMIT 5").fetchall()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
stats = c.execute("""
|
last_run = dict(last) if last else {}
|
||||||
SELECT agent, COUNT(*) as total,
|
|
||||||
SUM(CASE WHEN status='success' THEN 1 ELSE 0 END) as ok,
|
|
||||||
MAX(timestamp) as last_ts
|
|
||||||
FROM executions GROUP BY agent
|
|
||||||
""").fetchall()
|
|
||||||
|
|
||||||
conn.close()
|
asset_labels = {"btc": "Bitcoin", "usd": "Dólar USD/BRL", "xau": "Ouro XAU/USD"}
|
||||||
|
asset_emojis = {"btc": "₿", "usd": "💵", "xau": "🪙"}
|
||||||
|
asset_colors = {"btc": "#f7931a", "usd": "#4fc3f7", "xau": "#ffd700"}
|
||||||
|
|
||||||
# Busca último pipeline do ativo ou genérico
|
nodes = [
|
||||||
current_state = state.get_all()
|
{"id": "brief", "label": "Brief", "role": f"Inteligência {asset_labels.get(asset, asset)}",
|
||||||
last_run = dict(last) if last else {}
|
"emoji": asset_emojis.get(asset, "📊"), "color": asset_colors.get(asset, "#4fc3f7")},
|
||||||
|
{"id": "decio", "label": "Décio", "role": "Estrategista (CEO)",
|
||||||
|
"emoji": "🎯", "color": "#ffd54f"},
|
||||||
|
{"id": "papert", "label": "PaperT", "role": "Executor",
|
||||||
|
"emoji": "⚡", "color": "#69f0ae"},
|
||||||
|
{"id": "audit", "label": "Audit", "role": "Auditor Compliance",
|
||||||
|
"emoji": "🔍", "color": "#b388ff"},
|
||||||
|
]
|
||||||
|
|
||||||
asset_labels = {"btc": "Bitcoin", "usd": "Dólar USD/BRL", "xau": "Ouro XAU/USD"}
|
if last_run:
|
||||||
asset_emojis = {"btc": "₿", "usd": "💵", "xau": "🪙"}
|
current = {
|
||||||
asset_colors = {"btc": "#f7931a", "usd": "#4fc3f7", "xau": "#ffd700"}
|
"brief": {"status": last_run.get("brief_status", "done"), "message": last_run.get("brief_summary", "")[:80]},
|
||||||
|
"decio": {"status": last_run.get("decio_status", "done"), "message": last_run.get("decio_decision", "HOLD")},
|
||||||
|
"papert": {"status": last_run.get("papert_status", "done"), "message": last_run.get("papert_action", "-")},
|
||||||
|
"audit": {"status": last_run.get("audit_status", "done"), "message": last_run.get("audit_verdict", "APROVADO")},
|
||||||
|
}
|
||||||
|
for n in nodes:
|
||||||
|
st = current.get(n["id"], {}).get("status", "idle")
|
||||||
|
n["status"] = st
|
||||||
|
n["last_run"] = last_run.get("started_at", "")
|
||||||
|
else:
|
||||||
|
for n in nodes:
|
||||||
|
n["status"] = "idle"
|
||||||
|
|
||||||
nodes = [
|
recent_runs = [{
|
||||||
{"id": "brief", "label": "Brief", "role": f"Inteligência {asset_labels.get(asset, asset)}",
|
"started_at": r["started_at"],
|
||||||
"emoji": asset_emojis.get(asset, "📊"), "color": asset_colors.get(asset, "#4fc3f7")},
|
"decio_decision": r.get("decio_decision", "?"),
|
||||||
{"id": "decio", "label": "Décio", "role": "Estrategista (CEO)",
|
"status": r.get("status", "completed")
|
||||||
"emoji": "🎯", "color": "#ffd54f"},
|
} for r in last_5]
|
||||||
{"id": "papert", "label": "PaperT", "role": "Executor",
|
|
||||||
"emoji": "⚡", "color": "#69f0ae"},
|
|
||||||
{"id": "audit", "label": "Audit", "role": "Auditor Compliance",
|
|
||||||
"emoji": "🔍", "color": "#b388ff"},
|
|
||||||
]
|
|
||||||
|
|
||||||
if last_run:
|
return jsonify({"nodes": nodes, "recent_runs": recent_runs, "asset": asset})
|
||||||
current = {
|
except Exception as e:
|
||||||
"brief": {"status": last_run.get("brief_status", "done"), "message": last_run.get("brief_summary", "")[:80]},
|
app.logger.error(f"Pipeline visual asset error: {e}")
|
||||||
"decio": {"status": last_run.get("decio_status", "done"), "message": last_run.get("decio_decision", "HOLD")},
|
return jsonify({"error": str(e), "asset": asset}), 500
|
||||||
"papert": {"status": last_run.get("papert_status", "done"), "message": last_run.get("papert_action", "-")},
|
|
||||||
"audit": {"status": last_run.get("audit_status", "done"), "message": last_run.get("audit_verdict", "APROVADO")},
|
|
||||||
}
|
|
||||||
for n in nodes:
|
|
||||||
st = current.get(n["id"], {}).get("status", "idle")
|
|
||||||
n["status"] = st
|
|
||||||
n["last_run"] = last_run.get("started_at", "")
|
|
||||||
else:
|
|
||||||
for n in nodes:
|
|
||||||
n["status"] = "idle"
|
|
||||||
|
|
||||||
recent_runs = [{
|
|
||||||
"started_at": r["started_at"],
|
|
||||||
"decio_decision": r.get("decio_decision", "?"),
|
|
||||||
"status": r.get("status", "completed")
|
|
||||||
} for r in last_5]
|
|
||||||
|
|
||||||
return jsonify({"nodes": nodes, "recent_runs": recent_runs, "asset": asset})
|
|
||||||
|
|
||||||
# ── Multi-Asset: Portfolio Live ──────────────────────────────────────────────
|
# ── Multi-Asset: Portfolio Live ──────────────────────────────────────────────
|
||||||
@app.route("/api/portfolio/<asset>", methods=["GET"])
|
@app.route("/api/portfolio/<asset>", methods=["GET"])
|
||||||
|
|||||||
Reference in New Issue
Block a user