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
impl Supervisor
Sourcepub async fn request_action(
&self,
print_id: PrintId,
action: PrintAction,
) -> Result<ActionOutcome, CoreError>
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
impl Supervisor
Sourcepub async fn handle_event(
&self,
alert: NormalizedAlert,
) -> Result<EventRecord, CoreError>
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.
Sourcepub async fn context(
&self,
print_id: PrintId,
) -> Result<PrintContext, CoreError>
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
impl Supervisor
Sourcepub async fn sweep_expired(&self) -> Result<(), CoreError>
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.
Sourcepub async fn expire_intervention(
&self,
intervention: &Intervention,
) -> Result<InterventionOutcome, CoreError>
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
impl Supervisor
Sourcepub async fn list_and_adopt_prints(&self) -> Result<PrintListing, CoreError>
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 carries its file name.
Named for both halves, 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 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 for the job could not be opened.
Source§impl Supervisor
impl Supervisor
Sourcepub fn new(
config: CoreConfig,
printer: Arc<dyn PrinterPort>,
stores: Stores,
vision: Arc<dyn VisionPort>,
agent: Arc<dyn SupervisorPort>,
clock: Arc<dyn Clock>,
) -> Arc<Self> ⓘ
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.
Sourcepub const fn config(&self) -> &CoreConfig
pub const fn config(&self) -> &CoreConfig
The server configuration this supervisor runs under.