Watch
0
0
Fork
You've already forked hyperhive
0

matrix daemon: stay up when the primary account is down and say why in the tools

This commit is contained in:
damocles 2026-11-28 02:37:21 +01:00 • committed by mara
commit 73ef63a5e5

View file

@ -281,6 +281,8 @@ pub struct AccountStatus {
pub struct Registry {
primary: String,
by_name: RwLock<HashMap<String, Arc<Client>>>,
/// Why each account that is not up is not: what a tool call for it says.
down: RwLock<HashMap<String, String>>,
}
/// Pick which account name a request resolves to, or an error. Pure (no
@ -315,11 +317,31 @@ impl Registry {
Self {
primary,
by_name: RwLock::default(),
down: RwLock::default(),
}
}
/// The primary account's name.
#[must_use]
pub fn primary(&self) -> &str {
&self.primary
}
/// Note that `name` is not up, for `reason`, so a tool call for it can say
/// so instead of finding no such account.
pub fn note_down(&self, name: &str, reason: &str) {
self.down
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.insert(name.to_owned(), reason.to_owned());
}
/// Register a restored client under `name`.
pub fn insert(&self, name: String, client: Client) {
self.down
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.remove(&name);
self.by_name
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner)
@ -386,10 +408,19 @@ impl Registry {
names.sort_unstable();
let name = pick_name(account, &self.primary, &names)?;
clients.get(name).cloned().ok_or_else(|| {
format!(
"unknown matrix account {name:?}; available accounts: [{}]",
names.join(", ")
)
let down = self
.down
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner);
match down.get(name) {
Some(reason) => format!(
"matrix account {name:?} is not up: {reason}; the daemon keeps trying, so try the call again later"
),
None => format!(
"unknown matrix account {name:?}; available accounts: [{}]",
names.join(", ")
),
}
})
}