feat(alarmas): record and clear per-alarm scheduling failures
Adds ServicioAlarmas.registrarFalloProgramacion/limpiarFalloProgramacion, persisting a scheduling-reliability failure through the same ExcepcionAlarma model saltarProxima already uses. Only one failure record is kept per alarm (latest attempt wins) and skipNext entries for any alarm are never touched. EstadoAlarmas wiring follows next.
This commit is contained in:
@@ -350,6 +350,62 @@ class ServicioAlarmas {
|
||||
return nuevo;
|
||||
});
|
||||
|
||||
/// Records a scheduling-reliability failure for [alarmaId] (fix/alarmas-
|
||||
/// fallos-silenciosos): reuses the SAME `ExcepcionAlarma` model
|
||||
/// `saltarProxima` already persists, so `EstadoAlarmas.ultimaExcepcionPara`
|
||||
/// surfaces it on the exact alarm card affected instead of only a
|
||||
/// transient, alarm-agnostic message. A previous FAILURE record for the
|
||||
/// same alarm is replaced (only the latest attempt's outcome matters) --
|
||||
/// any `skipNext` exception for this or other alarms is left untouched.
|
||||
/// Never affects scheduling: `ServicioProgramacionAlarmas._esValida` only
|
||||
/// treats `tipoSaltoSiguiente` as an actual skip.
|
||||
Future<ConfiguracionAlarmas> registrarFalloProgramacion(
|
||||
String alarmaId,
|
||||
DateTime ejecucion,
|
||||
String tipo,
|
||||
) => _enCola(() async {
|
||||
final config = await _configActual();
|
||||
final excepciones = [
|
||||
..._sinFalloPrevio(config.excepciones, alarmaId),
|
||||
ExcepcionAlarma(alarmaId: alarmaId, ejecucion: ejecucion, tipo: tipo),
|
||||
];
|
||||
final nuevo = ConfiguracionAlarmas(
|
||||
alarmas: config.alarmas,
|
||||
vacaciones: config.vacaciones,
|
||||
excepciones: excepciones,
|
||||
);
|
||||
await _guardar(nuevo);
|
||||
return nuevo;
|
||||
});
|
||||
|
||||
/// Clears any outstanding failure record for [alarmaId] (a subsequent
|
||||
/// scheduling attempt succeeded). No-op when there is nothing to clear.
|
||||
Future<ConfiguracionAlarmas> limpiarFalloProgramacion(
|
||||
String alarmaId,
|
||||
) => _enCola(() async {
|
||||
final config = await _configActual();
|
||||
final sinFallo = _sinFalloPrevio(config.excepciones, alarmaId);
|
||||
if (sinFallo.length == config.excepciones.length) return config;
|
||||
final nuevo = ConfiguracionAlarmas(
|
||||
alarmas: config.alarmas,
|
||||
vacaciones: config.vacaciones,
|
||||
excepciones: sinFallo,
|
||||
);
|
||||
await _guardar(nuevo);
|
||||
return nuevo;
|
||||
});
|
||||
|
||||
List<ExcepcionAlarma> _sinFalloPrevio(
|
||||
List<ExcepcionAlarma> excepciones,
|
||||
String alarmaId,
|
||||
) => excepciones
|
||||
.where(
|
||||
(e) =>
|
||||
!(e.alarmaId == alarmaId &&
|
||||
ExcepcionAlarma.tiposFallo.contains(e.tipo)),
|
||||
)
|
||||
.toList();
|
||||
|
||||
Future<ConfiguracionAlarmas> posponerEjecucion(
|
||||
String alarmaId,
|
||||
DateTime ejecucion,
|
||||
|
||||
Reference in New Issue
Block a user