[FIX] Bitácora Web: Filtrar logs de PostgreSQL en heartbeats
Se implementó filtrado de output para que la Bitácora Web muestre solo las líneas relevantes del progreso del dron, no los ~40 logs repetitivos de conexión a PostgreSQL. Cambios: - filtrar_lineas_relevantes(): Filtra líneas de PostgreSQL en tiempo real - filtrar_output_relevante(): Filtra y mantiene últimas 20 líneas para heartbeat - Heartbeat web: Ahora muestra solo progreso del dron, no conexiones DB Beneficio: La Bitácora Web ahora muestra información útil y legible en lugar de cientos de líneas de logs técnicos repetitivos. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
db86f86e59
commit
b7ff2e7183
@@ -80,11 +80,11 @@ module Dron
|
||||
start_time = Time.now
|
||||
output = []
|
||||
last_out = ""
|
||||
accumulated_out = [] # Acumular todas las líneas de output para el heartbeat
|
||||
accumulated_out = [] # Acumular líneas relevantes para heartbeat web
|
||||
exit_code = nil
|
||||
progreso_visible = !ENV['BATCH_MODE'] # Solo mostrar progreso si no es batch
|
||||
progreso_visible = !ENV['BATCH_MODE']
|
||||
|
||||
# Mostrar encabezado de progreso
|
||||
# Mostrar encabezado de progreso (solo CLI)
|
||||
if progreso_visible
|
||||
puts "\n#{Color::BOLD}#{Color::CYAN}⏳ Ejecutando...#{Color::RESET}"
|
||||
print " ["
|
||||
@@ -102,10 +102,13 @@ module Dron
|
||||
# Actualizar tabla interna (dron_logs.heartbeat)
|
||||
ADN::DB::DronDB.actualizar_heartbeat(dron_id)
|
||||
|
||||
# Actualizar Bitácora Web (events.descripcion) — VISIBLE para el usuario
|
||||
actualizar_heartbeat_web(evento_id, dron_id, nota, cmd, inicio, tick, accumulated_out.join("\n")) if evento_id
|
||||
# Actualizar Bitácora Web con output filtrado (solo líneas relevantes)
|
||||
if evento_id
|
||||
output_filtrado = filtrar_output_relevante(accumulated_out)
|
||||
actualizar_heartbeat_web(evento_id, dron_id, nota, cmd, inicio, tick, output_filtrado.join("\n"))
|
||||
end
|
||||
|
||||
# Actualizar barra de progreso local
|
||||
# Actualizar barra de progreso local (solo CLI)
|
||||
if progreso_visible
|
||||
mins = elapsed / 60
|
||||
segs = elapsed % 60
|
||||
@@ -126,7 +129,9 @@ module Dron
|
||||
output << chunk
|
||||
lineas = chunk.split(/[\r\n]/).reject(&:empty?)
|
||||
last_out = lineas.last&.strip || last_out
|
||||
accumulated_out.concat(lineas) # Acumular líneas para heartbeat
|
||||
# Filtrar y acumular solo líneas relevantes (no PostgreSQL)
|
||||
lineas_relevantes = filtrar_lineas_relevantes(lineas)
|
||||
accumulated_out.concat(lineas_relevantes) unless lineas_relevantes.empty?
|
||||
end
|
||||
rescue EOFError, IOError
|
||||
end
|
||||
@@ -159,6 +164,33 @@ module Dron
|
||||
{ exit_code: exit_code || 1, output: safe_output, duration: (Time.now - start_time).round(2) }
|
||||
end
|
||||
|
||||
# ─── Filtrado de output para Bitácora Web ─────────────────────
|
||||
# Filtra líneas repetitivas de PostgreSQL y deja solo lo relevante
|
||||
|
||||
def filtrar_lineas_relevantes(lineas)
|
||||
lineas.reject do |linea|
|
||||
# Filtrar logs de conexión a PostgreSQL (son ~40 líneas repetitivas por dron)
|
||||
linea.include?('Conectando a PostgreSQL') ||
|
||||
linea.include?('Conexión a PostgreSQL establecida') ||
|
||||
linea.include?('Conexión a PostgreSQL cerrada') ||
|
||||
linea.include?('ℹ Conectando') ||
|
||||
linea.include?('ℹ Conexión')
|
||||
end
|
||||
end
|
||||
|
||||
def filtrar_output_relevante(accumulated_out)
|
||||
# Filtrar y dejar solo las últimas 20 líneas relevantes
|
||||
filtrado = accumulated_out.reject do |linea|
|
||||
linea.include?('Conectando a PostgreSQL') ||
|
||||
linea.include?('Conexión a PostgreSQL') ||
|
||||
linea.include?('ℹ Conectando') ||
|
||||
linea.include?('ℹ Conexión')
|
||||
end
|
||||
|
||||
# Mantener últimas 20 líneas para no saturar la bitácora
|
||||
filtrado.last(20) || []
|
||||
end
|
||||
|
||||
# ─── Bitácora Web: Crear/Vincular evento ─────────────────────
|
||||
|
||||
def crear_o_vincular_evento_web(dron_id, nota, evento_id, cmd, nodo)
|
||||
|
||||
Reference in New Issue
Block a user