hyperactor_mesh/
supervision.rs1use hyperactor::Bind;
12use hyperactor::Unbind;
13use hyperactor::actor::ActorErrorKind;
14use hyperactor::actor::ActorStatus;
15use hyperactor::context;
16use hyperactor::supervision::ActorSupervisionEvent;
17use serde::Deserialize;
18use serde::Serialize;
19use typeuri::Named;
20
21#[derive(Clone, Debug, Serialize, Deserialize, Named, PartialEq, Bind, Unbind)]
24pub struct MeshFailure {
25 pub actor_mesh_name: Option<String>,
27 pub rank: Option<usize>,
30 pub event: ActorSupervisionEvent,
32}
33wirevalue::register_type!(MeshFailure);
34
35impl MeshFailure {
36 pub fn default_handler(&self, cx: &impl context::Actor) -> Result<(), anyhow::Error> {
39 let err = ActorErrorKind::UnhandledSupervisionEvent(Box::new(ActorSupervisionEvent::new(
42 cx.instance().self_id().clone(),
43 None,
44 ActorStatus::Failed(ActorErrorKind::UnhandledSupervisionEvent(Box::new(
45 self.event.clone(),
46 ))),
47 None,
48 )));
49 Err(anyhow::Error::new(err))
50 }
51}
52
53impl std::fmt::Display for MeshFailure {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 let actor_mesh_name = self
56 .actor_mesh_name
57 .as_ref()
58 .map(|m| format!(" on mesh \"{}\"", m))
59 .unwrap_or("".to_string());
60 let rank = self
61 .rank
62 .as_ref()
63 .map(|r| format!(" at rank {}", r))
64 .unwrap_or("".to_string());
65 write!(
66 f,
67 "failure{}{} with event: {}",
68 actor_mesh_name, rank, self.event
69 )
70 }
71}
72
73#[derive(Debug, Clone)]
75pub(crate) enum Unhealthy {
76 StreamClosed(MeshFailure), Crashed(MeshFailure), }