Skip to main content

Transition

Enum Transition 

Source
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

Source

pub const ALL: [Transition; 6]

Every transition, in lifecycle order.

Source

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));
Source

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());
Source

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

Source§

fn clone(&self) -> Transition

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Transition

Source§

impl Debug for Transition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Transition

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Transition

Source§

impl Hash for Transition

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JsonSchema for Transition

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl Ord for Transition

Source§

fn cmp(&self, other: &Transition) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Transition

Source§

fn eq(&self, other: &Transition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Transition

Source§

fn partial_cmp(&self, other: &Transition) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Transition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Transition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more