docs & tools: Actualización de informes y scripts de migración DASUTEN

This commit is contained in:
Ricardo Monla
2026-04-20 16:25:51 -03:00
parent faf46be84b
commit 65dd92b769
44 changed files with 3822 additions and 568 deletions
+23 -5
View File
@@ -24,14 +24,14 @@ module Dron
HEARTBEAT_INTERVAL = 30
class << self
def lanzar(cmd:, nota: nil, evento_id: nil, timeout: DEFAULT_TIMEOUT, flujo_id: nil, nodo: nil)
def lanzar(cmd:, nota: nil, evento_id: nil, timeout: DEFAULT_TIMEOUT, flujo_id: nil, nodo: nil, ambito: nil)
Base.logger.info("🛠️ Dron Ejecutor iniciado: #{Process.pid}")
inicio = Time.now
# 1. Registrar en tablas internas (dron_logs)
resultado_inicio = ADN::DB::DronDB.registrar_inicio(
tipo: 'ejecutor', cmd: cmd, flujo_id: flujo_id,
metadata: { nota: nota, evento_id: evento_id, timeout: timeout, nodo: nodo }
metadata: { nota: nota, evento_id: evento_id, timeout: timeout, nodo: nodo, ambito: ambito }
)
dron_id = resultado_inicio[:dron_id]
@@ -42,7 +42,7 @@ module Dron
)
# 2. Crear/vincular evento en Bitácora Web (visible)
evento_id = crear_o_vincular_evento_web(dron_id, nota, evento_id, cmd, nodo)
evento_id = crear_o_vincular_evento_web(dron_id, nota, evento_id, cmd, nodo, ambito)
# 3. Ejecutar comando con heartbeat que actualiza AMBAS capas
resultado = ejecutar_comando(cmd, dron_id, timeout, evento_id, nota, inicio)
@@ -161,10 +161,11 @@ module Dron
# ─── Bitácora Web: Crear/Vincular evento ─────────────────────
def crear_o_vincular_evento_web(dron_id, nota, evento_id, cmd, nodo)
def crear_o_vincular_evento_web(dron_id, nota, evento_id, cmd, nodo, ambito = nil)
return nil unless nota # Sin nota = sin registro en web
nodo_id = detectar_nodo_id(nodo)
ambito_id = detectar_ambito_id(ambito)
BitacorasDB::BitacoraDB.with_connection do |db|
if evento_id.to_i > 0
@@ -196,12 +197,14 @@ module Dron
estado: '⏳',
modo: 'P',
bitacora_id: bitacora_hoy['id'],
nodo_id: nodo_id
nodo_id: nodo_id,
ambito_id: ambito_id
)
entrada['id']
else
evento = db.crear_evento(
nodo_id: nodo_id,
ambito_id: ambito_id,
descripcion: descripcion,
inicio: Time.now.strftime('%H:%M'),
estado: '⏳',
@@ -307,6 +310,21 @@ module Dron
Base.logger.warn("⚠️ Error detectando nodo: #{e.message}, usando default (1)")
1
end
def detectar_ambito_id(ambito)
return ambito if ambito.is_a?(Integer)
return nil if ambito.nil? || ambito.empty?
resultado = nil
BitacorasDB::BitacoraDB.with_connection do |db|
resultado = db.execute('SELECT id FROM bitacoras.ambitos WHERE LOWER(nombre) = $1 LIMIT 1', [ambito.downcase])
end
resultado&.any? ? resultado.first['id'] : nil
rescue StandardError => e
Base.logger.warn("⚠️ Error detectando ámbito: #{e.message}, usando default (nil)")
nil
end
end
end
end