feat(event): add business control events (fault, comm, auto, state change)
This commit is contained in:
parent
684ca9da85
commit
68e724898c
70
src/event.rs
70
src/event.rs
|
|
@ -34,6 +34,13 @@ pub enum AppEvent {
|
|||
unit_id: Option<Uuid>,
|
||||
point_id: Uuid,
|
||||
},
|
||||
AutoControlStarted { unit_id: Uuid },
|
||||
AutoControlStopped { unit_id: Uuid },
|
||||
FaultLocked { unit_id: Uuid, equipment_id: Uuid },
|
||||
FaultAcked { unit_id: Uuid },
|
||||
CommLocked { unit_id: Uuid },
|
||||
CommRecovered { unit_id: Uuid },
|
||||
UnitStateChanged { unit_id: Uuid, from_state: String, to_state: String },
|
||||
PointNewValue(crate::telemetry::PointNewValue),
|
||||
}
|
||||
|
||||
|
|
@ -219,6 +226,27 @@ async fn handle_control_event(
|
|||
point_id
|
||||
);
|
||||
}
|
||||
AppEvent::AutoControlStarted { unit_id } => {
|
||||
tracing::info!("Auto control started for unit {}", unit_id);
|
||||
}
|
||||
AppEvent::AutoControlStopped { unit_id } => {
|
||||
tracing::info!("Auto control stopped for unit {}", unit_id);
|
||||
}
|
||||
AppEvent::FaultLocked { unit_id, equipment_id } => {
|
||||
tracing::warn!("Fault locked: unit={}, equipment={}", unit_id, equipment_id);
|
||||
}
|
||||
AppEvent::FaultAcked { unit_id } => {
|
||||
tracing::info!("Fault acked for unit {}", unit_id);
|
||||
}
|
||||
AppEvent::CommLocked { unit_id } => {
|
||||
tracing::warn!("Comm locked for unit {}", unit_id);
|
||||
}
|
||||
AppEvent::CommRecovered { unit_id } => {
|
||||
tracing::info!("Comm recovered for unit {}", unit_id);
|
||||
}
|
||||
AppEvent::UnitStateChanged { unit_id, from_state, to_state } => {
|
||||
tracing::info!("Unit {} state: {} → {}", unit_id, from_state, to_state);
|
||||
}
|
||||
AppEvent::PointNewValue(_) => {
|
||||
tracing::warn!("PointNewValue routed to control worker unexpectedly");
|
||||
}
|
||||
|
|
@ -310,6 +338,48 @@ async fn persist_event_if_needed(
|
|||
"point_id": point_id
|
||||
}),
|
||||
)),
|
||||
AppEvent::AutoControlStarted { unit_id } => Some((
|
||||
"unit.auto_control_started", "info",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Auto control started for unit {}", unit_id),
|
||||
serde_json::json!({ "unit_id": unit_id }),
|
||||
)),
|
||||
AppEvent::AutoControlStopped { unit_id } => Some((
|
||||
"unit.auto_control_stopped", "info",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Auto control stopped for unit {}", unit_id),
|
||||
serde_json::json!({ "unit_id": unit_id }),
|
||||
)),
|
||||
AppEvent::FaultLocked { unit_id, equipment_id } => Some((
|
||||
"unit.fault_locked", "error",
|
||||
Some(*unit_id), Some(*equipment_id), None,
|
||||
format!("Unit {} fault locked by equipment {}", unit_id, equipment_id),
|
||||
serde_json::json!({ "unit_id": unit_id, "equipment_id": equipment_id }),
|
||||
)),
|
||||
AppEvent::FaultAcked { unit_id } => Some((
|
||||
"unit.fault_acked", "info",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Unit {} fault acknowledged", unit_id),
|
||||
serde_json::json!({ "unit_id": unit_id }),
|
||||
)),
|
||||
AppEvent::CommLocked { unit_id } => Some((
|
||||
"unit.comm_locked", "warn",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Unit {} communication locked", unit_id),
|
||||
serde_json::json!({ "unit_id": unit_id }),
|
||||
)),
|
||||
AppEvent::CommRecovered { unit_id } => Some((
|
||||
"unit.comm_recovered", "info",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Unit {} communication recovered", unit_id),
|
||||
serde_json::json!({ "unit_id": unit_id }),
|
||||
)),
|
||||
AppEvent::UnitStateChanged { unit_id, from_state, to_state } => Some((
|
||||
"unit.state_changed", "info",
|
||||
Some(*unit_id), None, None,
|
||||
format!("Unit {} state: {} → {}", unit_id, from_state, to_state),
|
||||
serde_json::json!({ "unit_id": unit_id, "from": from_state, "to": to_state }),
|
||||
)),
|
||||
AppEvent::PointNewValue(_) => None,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue