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.

A start may be made against a print other than print_id: it is recorded against Self::print_to_start’s, which the answer’s record names.

Source§

impl Supervisor

Source

pub async fn resume_due_detector_pauses(&self)

Resume every print whose resume has come due.

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 — except the writes that come after the event is already in the history and are owed the spool ledger: a new print’s print_started, and what a filament-change signal the alert relays charges and marks. Those are answered as the store’s own error, the alert itself already written.

Source

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

Write one normalized event down, and say whether it needs a turn of its own.

The first half of Supervisor::handle_event, for a caller that runs the turn somewhere else so that the next event can be written down while this one’s turn is still running. An event for a print whose turn is already running is handed to that turn and answers no turn of its own: one agent per print, and what arrives reaches the agent already watching it.

§Errors

Exactly as Supervisor::handle_event’s.

Source

pub async fn run_supervision(&self, turn: PendingTurn) -> Result<(), CoreError>

Run the turn one received event claimed, and one more for whatever arrived during it that it never took, until nothing is left.

The detector’s pause the agent adjusted the print under is resumed as each turn ends, when its grace has not already resumed it.

§Errors

Returns the store’s own error when a turn’s outcome could not be recorded; a turn that fails is recorded rather than answered.

Source

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

Gather the current context of one print, including while its supervision turn is running.

§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 whose time has passed.

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. Its first sweep reads the interventions a previous supervisor left active and counts each down from the reading this supervisor took as it started; every later one reads nothing, because every intervention opened since is counted down from the moment it was applied.

§Errors

Returns the store’s own error when the interventions left active could not be read, which the next sweep reads again. 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 async fn list_and_adopt_prints(&self) -> Result<PrintListing, CoreError>

Every print, and the one the printer’s job belongs to — opening one for that job when no open print records it, and closing the open prints the printer’s job shows are over.

Named for the half a caller sees, because it is not only a read: the listing is what a caller asked for, and the print it may open is what makes that listing name the job at all. A printer that cannot be read is a listing with nothing active, and nothing closed, rather than a failure: the stored prints are still the answer to which prints there are.

§Errors

Returns the store’s own error when the prints could not be read, or a print could not be opened or closed.

Source

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

Close every open print the printer’s job shows is over, and record the running job’s start on the open print it is.

What a supervisor does with the printer as it starts, before it adopts what is left open: a print that ended while nothing was watching is not one to go on watching. A printer that cannot be read settles nothing.

§Errors

Returns the store’s own error when the open prints could not be read or a print could not be closed.

Source§

impl Supervisor

Source

pub fn await_arrivals(&self, print_id: PrintId, wait: Duration) -> Vec<Arrival>

Wait up to wait for anything to arrive for one print’s running turn, and take it.

This blocks the calling thread for as long as it waits; call it where a blocking wait is expected.

Source

pub async fn take_look( &self, print_id: PrintId, waited: Duration, arrived: Vec<Arrival>, ) -> Result<Look, CoreError>

Take a frame, write one look down with it, and read the printer.

§Errors

Returns CoreError::NoSuchPrint when nothing is held under that identifier, and the store’s own error when the look could not be written down. A camera or printer that will not answer is recorded and answered as an absence rather than as an error.

What arrived is delivered by the look written down, so a look that could not be written down delivers nothing: what it was handed goes back to the print’s running turn, ahead of anything that arrived since, for its next look or the turn after it.

Source

pub async fn take_printer_look( &self, waited: Duration, ) -> Result<Look, CoreError>

Take a frame of the printer with no print named, write the look down with it, and read the printer.

The look and its frame belong to no print. Nothing is waited on here and nothing is delivered: a look at the printer takes no event any print’s agent is owed.

§Errors

Returns the store’s own error when the look could not be written down. A camera or printer that will not answer is recorded and answered as an absence rather than as an error.

Source§

impl Supervisor

Source

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

Observe every active print nobody is watching, and answer the turns those observations claimed.

One print’s observation that could not be written down is answered in Observed::refused and stops no other: every turn the round claimed is answered, because a claimed turn nobody runs is a print no later event could reach.

§Errors

Returns the store’s own error when the open prints could not be read or settled, before any print was claimed.

Source§

impl Supervisor

Source

pub async fn preflight( &self, file_name: &FileName, sheet: Option<&SheetId>, ) -> Result<Preflight, CoreError>

Whether the spools loaded hold enough for one file, read now.

A read: it records nothing and never waits. A file whose facts cannot be read is a file with no analysis.

§Errors

Returns the store’s own error when the loaded spools could not be read.

Source§

impl Supervisor

Source

pub fn z_trust(&self) -> ZTrust

Whether Z is trusted now, and since when or why not.

Source

pub async fn request_recovery( &self, action: RecoveryAction, actor: Actor, reason: String, ) -> Result<RecoveryIssued, CoreError>

Carry out one recovery action, or refuse it, recording either.

§Errors

Returns the store’s own error when the request or what became of it could not be recorded. A refusal is not an error: it is recorded and answered in RecoveryIssued::decision.

Source

pub async fn recovery_status( &self, class: ActorClass, ) -> Result<RecoveryStatus, CoreError>

Everything a recovery is checked against now, and what each action would meet, for one actor class.

§Errors

Returns the store’s own error when the prints or the events could not be read.

Source§

impl Supervisor

Source

pub async fn request_spool_command( &self, command: SpoolCommand, ) -> Result<SpoolCommandOutcome, CoreError>

Carry out one spool command, through the same grant every action passes.

§Errors

Returns the store’s own error when the command or its refusal could not be written. A refusal is not an error: it is written down and answered in SpoolCommandOutcome::decision.

Source

pub async fn spools( &self, include_retired: bool, ) -> Result<Vec<SpoolRecord>, CoreError>

Every spool, retired ones only when asked for, most recently registered first.

§Errors

Returns the store’s own error when the spools could not be read.

Source

pub async fn spool( &self, spool_id: SpoolId, ) -> Result<Option<SpoolRecord>, CoreError>

One spool, retired or not.

§Errors

Returns the store’s own error when the spool could not be read.

Source

pub async fn timeline( &self, query: TimelineQuery, ) -> Result<Vec<EventRecord>, CoreError>

The printer timeline, newest first.

§Errors

Returns the store’s own error when the timeline could not be read, a kind outside the timeline or a limit above the maximum included.

Source

pub async fn pending_charges( &self, tool: Option<i64>, ) -> Result<Vec<PendingCharge>, CoreError>

Every charge held after an unconfirmed filament change — on one tool, when one is named — oldest first.

§Errors

Returns the store’s own error when the charges could not be read.

Source§

impl Supervisor

Source

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

Build a supervisor over the three ports and the stores, 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 fn install_turn_authority(&self, authority: Arc<dyn TurnAuthority>) -> bool

Install where every supervision turn’s runs take their credentials from. The first installation stands; answers whether this one did.

Source

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

The server configuration this supervisor runs under.

Source§

impl Supervisor

Source

pub async fn account_unobserved_prints( &self, ) -> Result<Vec<EventRecord>, CoreError>

Account the prints the printer’s tallies counted that this system never saw, and answer what that recorded.

§Errors

Returns the printer’s own error when its tallies could not be read, and the store’s own when the accounting could not be written — in which case nothing of this run was.

Source§

impl Supervisor

Source

pub fn detector_health(&self) -> DetectorHealth

The failure detector’s health, as the last check found it.

Source

pub fn note_push_channel(&self, open: Result<(), String>)

Report that the printer’s push channel opened, or why it is down.

While it is down an ending is decided from the printer’s state alone, and every event the watch writes says so.

Source

pub async fn note_push(&self, push: PrinterPush) -> Result<(), CoreError>

Take one thing the printer pushed.

A reset is recorded at once as a PrinterResetPayload, naming the print it happened during when one was running; it and an error of the printer’s own are kept for the close-out of the print they stopped. Terminal lines are the server’s to read, and are ignored here.

§Errors

Returns the store’s own error when the reset could not be recorded.

Source

pub async fn watch_printer( &self, probe: &dyn PositionProbe, ) -> Result<Watched, CoreError>

Read the machine once, record what changed, and answer the turns that claimed.

A printer whose job cannot be read changes nothing: an instance that does not answer says nothing about the machine behind it.

§Errors

Returns the store’s own error when what changed could not be recorded.

Source

pub async fn check_detector( &self, probe: &dyn DetectorProbe, ) -> Result<Option<PendingTurn>, CoreError>

Ask the failure detector whether it is answering, during a print, and record each change; going unavailable claims the active print’s agent a turn.

No print open, no check: a detector nobody needs is not one to record.

§Errors

Returns the store’s own error when a change could not be recorded.

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.