feat(nexxa): estado en su Postgres propio con Nexxa::Estado (motores archivo|pg), mutar atómico y dispensa en un paso; 1.7.0 (P335/F17)
Tests ADN / test (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Co-Authored-By: GEMMA <noreply@gemma.dtic>
This commit is contained in:
Ricardo Monla
2026-10-05 02:37:26 -03:00
co-authored by Claude Opus 5.5 GEMMA
parent 4df538283f
commit 84d51ed669
13 changed files with 904 additions and 270 deletions
+5 -13
View File
@@ -10,10 +10,11 @@
require 'json'
require 'time'
require_relative 'lib_estado'
module Nexxa
module Usos
LOG_FILE = File.expand_path('usos.log', __dir__).freeze
LOG_FILE = Estado::USOS_LOG # fuente única de la ruta (P335/Fase 17)
# evento (P204/Fase3): 'dispensada' (reserva al entregar la key) o 'agotada'
# (el consumidor reportó agotamiento real) — default compat con llamadas
@@ -26,21 +27,12 @@ module Nexxa
'evento' => evento,
'en' => en.iso8601
}
File.open(LOG_FILE, 'a') { |f| f.puts(linea.to_json) }
Estado.usos_registrar(linea)
end
# Historial más reciente primero, opcionalmente filtrado por key
# Historial más reciente primero, opcionalmente filtrado por key (Nexxa::Estado, P335/Fase 17)
def self.historial(provider: nil, identificador: nil, limit: 50)
return [] unless File.exist?(LOG_FILE)
lineas = File.readlines(LOG_FILE).filter_map do |l|
JSON.parse(l)
rescue JSON::ParserError
nil
end
lineas.select! { |l| l['provider'] == provider } if provider
lineas.select! { |l| l['identificador'] == identificador } if identificador
lineas.last(limit).reverse
Estado.usos_historial(provider: provider, identificador: identificador, limit: limit)
end
end
end