Skip to main content

Supervisor

Struct Supervisor 

Source
pub struct Supervisor { /* private fields */ }
Expand description

The supervision core: one printer, one store, one agent, one clock.

Built with Supervisor::new, which answers a shared handle because the expiry driver holds a weak reference to it: a bounded intervention expires with nothing asking it to, and the driver is the thread that makes that so.

Implementations§

Source§

impl Supervisor

Source

pub async fn request_action( &self, print_id: PrintId, action: PrintAction, ) -> Result<ActionOutcome, CoreError>

Request one action against one print.

The same call an operator’s action makes, an agent’s action makes and a client’s action makes. A rejected request reaches no action method of the printer port at all, and the rejection is persisted carrying its own reason so that the caller can ask again inside the range.

§Errors

Returns the store’s own error when the decision, the execution or the intervention could not be recorded. A refusal by the printer is not an error: it is recorded and reported in ActionOutcome::executed.

Source§

impl Supervisor

Source

pub async fn handle_event( &self, alert: NormalizedAlert, ) -> Result<EventRecord, CoreError>

Handle one normalized event, from the store’s own append to the turn.

§Errors

Returns the store’s own error when the initial event append fails, which is the one failure this loop cannot record anywhere; no other port is called for that event, and a later event whose append succeeds is handled to completion. Every other port failure this loop reaches is recorded against the event rather than answered here.

Source

pub async fn context( &self, print_id: PrintId, ) -> Result<PrintContext, CoreError>

Everything a supervision turn is given about one print.

While a turn is running for the print, this answers the context the loop collected for the event that prompted it.

§Errors

Returns CoreError::NoSuchPrint when nothing is held under that identifier, and the store’s own error when the context could not be read.

Source§

impl Supervisor

Source

pub async fn sweep_expired(&self) -> Result<(), CoreError>

Expire every bounded intervention that is due at the clock’s own instant.

One intervention’s failure does not cost the rest: every one that is due is attempted on the same sweep.

The expiry driver calls this on its own poll, and a composition root calls it once on start so that an intervention left past its expiry by a restart is expired then rather than up to one poll later.

§Errors

Returns the store’s own error when the due interventions could not be read. A failure settling one of them is recorded on that intervention rather than answered here.

Source

pub async fn expire_intervention( &self, intervention: &Intervention, ) -> Result<InterventionOutcome, CoreError>

Expire one intervention: restore, report nothing to restore, or record that the restoration failed.

Settling is once-only, so an intervention this and the expiry driver both reach answers the outcome that won rather than being restored twice. That is what lets a composition root expire what a restart left past its bound and record the outcome, whichever of the two got there first.

§Errors

Returns the store’s own error when the outcome could not be settled.

Source§

impl Supervisor

Source

pub fn new( config: CoreConfig, printer: Arc<dyn PrinterPort>, store: Arc<dyn StorePort>, vision: Arc<dyn VisionPort>, agent: Arc<dyn SupervisorPort>, clock: Arc<dyn Clock>, ) -> Arc<Self> ⓘ

Build a supervisor over the four ports, and start its expiry driver.

The driver is a thread of core’s own holding a weak reference, so it stops of its own accord when the last handle to the supervisor is dropped. It reads the injected clock and nothing else, which is what makes a bounded intervention expire with nothing asking it to.

§Panics

Panics when the operating system refuses to start that thread, which is a supervisor whose bounded interventions would never expire — the one state this crate must not come up in quietly.

Source

pub const fn config(&self) -> &CoreConfig

The server configuration this supervisor runs under.

Trait Implementations§

Source§

impl Debug for Supervisor

Source§

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

Formats the value using the given formatter. Read more

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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.