Files
dag_engine_ui/data_http.h
T
egutierrez 4abc3f97ec chore: auto-commit (8 archivos)
- CMakeLists.txt
- app.md
- data_http.cpp
- data_http.h
- main.cpp
- tabs.cpp
- tabs.h
- appicon.ico

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 16:33:23 +02:00

110 lines
3.6 KiB
C++

#pragma once
// Cliente HTTP REST contra apps/dag_engine (Go backend).
// Endpoints: /api/dags, /api/runs, /api/dags/{name}/run (issue 0095).
#include <string>
#include <vector>
namespace dag_ui {
// --- Modelo de datos (mirror JSON shape de apps/dag_engine) ---
struct DagRunRow; // fwd
struct DagInfo {
std::string name;
std::string description;
std::vector<std::string> schedule; // cron expressions
std::vector<std::string> tags;
std::string type;
std::string file_path;
bool valid = false;
// last_run inlined fields (extracted from nested object on load)
bool has_last_run = false;
std::string last_run_id;
std::string last_run_status;
std::string last_run_started_at;
std::string last_run_finished_at;
// last_runs[] (max 5, most recent first). Empty if no runs yet.
// Populated from /api/dags `last_runs` array.
std::vector<std::string> last_runs_status; // parallel: status of each (size <= 5)
};
struct DagRunRow {
std::string id;
std::string dag_name;
std::string dag_path;
std::string status; // pending|running|success|failed|cancelled
std::string trigger; // manual|cron|api
std::string started_at;
std::string finished_at;
std::string error;
};
struct DagStepRow {
std::string id;
std::string run_id;
std::string step_name;
std::string status;
int exit_code = 0;
std::string stdout_text;
std::string stderr_text;
std::string started_at;
std::string finished_at;
long long duration_ms = 0;
std::string error;
std::string function_id; // "" if not a function step
};
// Metadata de una funcion del registry (response shape de GET /api/functions/{id}).
struct FnInfo {
std::string id;
std::string name;
std::string description;
std::string signature;
std::string purity; // "pure" | "impure"
std::string domain;
std::string lang;
std::vector<std::string> uses_functions;
std::vector<std::string> uses_types;
};
struct DagRunDetail {
DagRunRow run;
std::vector<DagStepRow> steps;
};
struct DagDetail {
DagInfo info;
std::vector<DagRunRow> recent_runs;
std::string validation_error; // empty if valid
};
// --- API ---
// api_url: "http://127.0.0.1:8090". Todas las funciones blocking, devuelven
// false si la red falla o el status no es 2xx. Errores van a stderr.
bool list_dags_http(const std::string& api_url, std::vector<DagInfo>& out);
bool get_dag_http(const std::string& api_url, const std::string& name,
DagDetail& out);
bool list_runs_http(const std::string& api_url, const std::string& dag_name,
int limit, std::vector<DagRunRow>& out);
bool get_run_http(const std::string& api_url, const std::string& run_id,
DagRunDetail& out);
// Devuelve el run_id en out_run_id si HTTP 202.
bool trigger_dag_http(const std::string& api_url, const std::string& name,
std::string& out_run_id, std::string& out_error);
// GET /api/functions/{function_id} -> rellena out con metadata del registry.
// Devuelve false si red falla, status != 2xx, o JSON no parseable.
bool get_function_http(const std::string& api_url,
const std::string& function_id,
FnInfo& out);
} // namespace dag_ui