mule/peer
The leadership read surface, mirroring Oban.Peer. A record of closures,
like engine.Engine and notifier.Notifier, so each backend swaps its own
implementation in at startup: the Postgres backend wires these to the
lease-election peer actor’s cell + a database read, and the in-memory /
single-node backend uses always_leader.
The leader-only gates (cron, pruner, the stager) call is_leader on their
hot path, so it must be a pure cell read — never a database round-trip,
never a blocking call into the actor (which would panic on restart; see
peer/cell). get_leader mirrors Oban.Peer.get_leader, which does
query the database, and is never called from a gate.
Types
pub type Peer {
Peer(
is_leader: fn() -> Bool,
get_leader: fn() -> option.Option(String),
)
}
Constructors
-
Peer( is_leader: fn() -> Bool, get_leader: fn() -> option.Option(String), )Arguments
- is_leader
-
Is this node the leader right now? A pure in-memory cell read: never touches the database, never blocks, never panics;
Falsewhen the cell has no entry (no election has run). MirrorsOban.Peer.leader?. - get_leader
-
The current leader’s node string, or
None. MirrorsOban.Peer.get_leader, which queries the database — so this may do a DB round-trip and must not be used on any gate’s hot path.
Values
pub fn always_leader(node node: String) -> Peer
The single-node / in-memory backend: always leader, backed by no actor and
no table. Used directly by mule.start for the in-memory engine.
pub fn put_is_leader(
instance_name instance_name: String,
is_leader is_leader: Bool,
) -> Nil
Cache this node’s leadership for instance_name. Called by the peer actor
on every election so the gates always see fresh state.
pub fn read_is_leader(
instance_name instance_name: String,
) -> Bool
Read this node’s cached leadership for instance_name (False when no
election has populated the cell). The total read the is_leader closure is
built from.