Skip to main content

hennery_kernel/
lifecycle.rs

1//! Lifecycle hooks (kernel spec §5.5): what the kernel's own operations
2//! require of the modules that own session and gateway state. They
3//! implement the trait, so the kernel never imports them.
4
5/// Called by the kernel's lifecycle operations once the kernel's own part
6/// is done.
7pub trait LifecycleHooks: Send + Sync {
8    /// The host is revoked and its connection is gone (kernel spec §4.3):
9    /// nothing it held will ever be reconciled. Must be idempotent: a
10    /// repeated revoke calls it again.
11    fn on_host_revoked(&self, host_id: &str) -> anyhow::Result<()>;
12
13    /// The hat is frozen for its purge (kernel spec §5.5; plan 9c decision
14    /// 10d): delete everything of it the module keeps, before the kernel
15    /// deletes the hat's row. Runs in transactions of its own. Must be
16    /// idempotent: a purge that stopped is resumed by running it again. An
17    /// error leaves the hat frozen, for a later purge to resume.
18    fn on_hat_purged<'a>(&'a self, hat_id: &'a str) -> Purge<'a>;
19}
20
21/// Purge releases all gates/transactions before bounded external lifecycle I/O.
22pub type Purge<'a> = std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + Send + 'a>>;