pub enum Transition {
Open,
Resume,
Checkpoint,
Detach,
Close,
Recover,
}Expand description
What moved an episode. The vocabulary the ADR 0052 audit needs: open, resume,
checkpoint, detach, close, recover.
One of them does not change the state, and it is a transition anyway. A checkpoint
leaves an open episode open — but it is one of the two events whose absence is what
the audit was looking for, and an event that is modelled as “nothing happened” cannot
be counted. The six days of silence were six days in which session.started and
session.closed kept arriving and the two events that produce the records a worker
resumes from did not. A vocabulary in which those two are not events is a vocabulary in
which that outage is invisible.
use majordomus_cli::session::{EpisodeState, Transition};
// a checkpoint is a transition that does not move the state, and says so
let c = Transition::Checkpoint;
assert_eq!(c.from_to(), (EpisodeState::Open, EpisodeState::Open));
assert!(!c.moves_state());
// a resume is canonically the return to a detached episode; a provider's start event
// arriving at one that is already open is the same transition seen from `Open`, which
// the machine allows without a move
assert_eq!(Transition::Resume.from_to(), (EpisodeState::Detached, EpisodeState::Open));
assert!(EpisodeState::Open.may_move_to(EpisodeState::Open));
// and every transition's own move is one the machine allows
for t in Transition::ALL {
let (from, to) = t.from_to();
assert!(from.may_move_to(to), "{} is not a legal move", t.as_str());
}Variants§
Open
The episode begins: an id is minted and the open record is written.
Resume
The worker came back to a detached episode. A provider’s start event also fires
again on a resume and on a compaction against an episode that is still open; that
is the same transition observed from Open, and the honest answer to “your episode
is already open” is to keep it rather than to open a second one.
Checkpoint
A progress note was recorded against the episode. An artefact of the episode and
not of a task (ADR 0052): a checkpoint outside a task records task: none and is a
normal record, not a refusal.
Detach
The connection went away without an end event.
Close
The worker ended the episode and the immutable record was published.
Recover
Nobody ended it and its last sign of life is older than the stranded threshold, so
maintenance closed it. The record says so: an episode closed this way is
interrupted, because a reader resuming from it needs to know it may be incomplete.
Implementations§
Source§impl Transition
impl Transition
Sourcepub const ALL: [Transition; 6]
pub const ALL: [Transition; 6]
Every transition, in lifecycle order.
Sourcepub fn from_to(self) -> (EpisodeState, EpisodeState)
pub fn from_to(self) -> (EpisodeState, EpisodeState)
The states this transition runs between: where an episode must be for it to apply, and where it is afterwards.
use majordomus_cli::session::{EpisodeState, Transition};
assert_eq!(Transition::Close.from_to(), (EpisodeState::Open, EpisodeState::Closed));
assert_eq!(Transition::Detach.from_to(), (EpisodeState::Open, EpisodeState::Detached));Sourcepub fn moves_state(self) -> bool
pub fn moves_state(self) -> bool
Does this transition change the state, or is it an event inside one? A checkpoint is the second kind, and it is a transition anyway: an event modelled as “nothing happened” cannot be counted, and counting it is how a stopped writer becomes visible.
use majordomus_cli::session::Transition;
assert!(!Transition::Checkpoint.moves_state());
assert!(Transition::Close.moves_state());Sourcepub fn as_str(self) -> &'static str
pub fn as_str(self) -> &'static str
The word as serialised, which is what a projection of the machine carries and what a ledger event’s name is read against.
use majordomus_cli::session::Transition;
assert_eq!(Transition::Recover.as_str(), "recover");
assert_eq!(Transition::Checkpoint.as_str(), "checkpoint");Trait Implementations§
Source§impl Clone for Transition
impl Clone for Transition
Source§fn clone(&self) -> Transition
fn clone(&self) -> Transition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Transition
Source§impl Debug for Transition
impl Debug for Transition
Source§impl<'de> Deserialize<'de> for Transition
impl<'de> Deserialize<'de> for Transition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Transition
Source§impl Hash for Transition
impl Hash for Transition
Source§impl JsonSchema for Transition
impl JsonSchema for Transition
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Transition
impl Ord for Transition
Source§fn cmp(&self, other: &Transition) -> Ordering
fn cmp(&self, other: &Transition) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Transition
impl PartialEq for Transition
Source§fn eq(&self, other: &Transition) -> bool
fn eq(&self, other: &Transition) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for Transition
impl PartialOrd for Transition
Source§impl Serialize for Transition
impl Serialize for Transition
impl StructuralPartialEq for Transition
Auto Trait Implementations§
impl Freeze for Transition
impl RefUnwindSafe for Transition
impl Send for Transition
impl Sync for Transition
impl Unpin for Transition
impl UnsafeUnpin for Transition
impl UnwindSafe for Transition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.