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"])
|
||||
def pipeline_visual_asset(asset):
|
||||
"""Pipeline visual específico por ativo (USD/XAU simulado via DB)."""
|
||||
conn = _db_conn(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
try:
|
||||
conn = _db_conn(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
||||
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 = 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()
|
||||
conn.close()
|
||||
|
||||
stats = c.execute("""
|
||||
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()
|
||||
last_run = dict(last) if last else {}
|
||||
|
||||
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
|
||||
current_state = state.get_all()
|
||||
last_run = dict(last) if last else {}
|
||||
nodes = [
|
||||
{"id": "brief", "label": "Brief", "role": f"Inteligência {asset_labels.get(asset, asset)}",
|
||||
"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"}
|
||||
asset_emojis = {"btc": "₿", "usd": "💵", "xau": "🪙"}
|
||||
asset_colors = {"btc": "#f7931a", "usd": "#4fc3f7", "xau": "#ffd700"}
|
||||
if last_run:
|
||||
current = {
|
||||
"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 = [
|
||||
{"id": "brief", "label": "Brief", "role": f"Inteligência {asset_labels.get(asset, asset)}",
|
||||
"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"},
|
||||
]
|
||||
recent_runs = [{
|
||||
"started_at": r["started_at"],
|
||||
"decio_decision": r.get("decio_decision", "?"),
|
||||
"status": r.get("status", "completed")
|
||||
} for r in last_5]
|
||||
|
||||
if last_run:
|
||||
current = {
|
||||
"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"
|
||||
|
||||
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})
|
||||
return jsonify({"nodes": nodes, "recent_runs": recent_runs, "asset": asset})
|
||||
except Exception as e:
|
||||
app.logger.error(f"Pipeline visual asset error: {e}")
|
||||
return jsonify({"error": str(e), "asset": asset}), 500
|
||||
|
||||
# ── Multi-Asset: Portfolio Live ──────────────────────────────────────────────
|
||||
@app.route("/api/portfolio/<asset>", methods=["GET"])
|
||||
|
||||
Reference in New Issue
Block a user