Skip to main content

CapabilityExecutor

Struct CapabilityExecutor 

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

The executor of one registry.

Implementations§

Source§

impl CapabilityExecutor

Source

pub fn new() -> Self

An executor with an empty cache.

Source

pub fn execute( &self, ctx: &Context, id: &str, input: Value, ) -> Result<Value, CapabilityError>

Execute a capability by id with a JSON input. The one place a handler runs.

Source

pub fn execute_uncached( &self, ctx: &Context, id: &str, input: Value, ) -> Result<Value, CapabilityError>

The same call with the cache stepped over: the handler runs, whatever is stored.

One caller: the execution engine. A cached answer is indistinguishable from a fresh one — that is the point of the cache and the rule project.cache-is-invisible says so — but an execution is not an answer. It is a record of work happening, watched while it happens, and an execution answered from a cache would report no steps, no progress and no output of its own while claiming to have succeeded: a story of work that did not occur. So an execution always runs the handler, and nothing it produces is put into the cache either, because the cache holds what calls returned and this call is a different kind of thing.

Source

pub fn writes(&self) -> u64

How many calls of a capability whose effect is a repository mutation have succeeded through this executor.

A write to a tracked file moves no git control file, so a long-lived process that follows the repository by those files would go on answering from the picture it had before its own write. The executor outlives a reload, so this number is what crate::live compares: when it has moved, the process wrote, and the next reading is a new generation.

use majordomus_cli::capability::executor::CapabilityExecutor;
let executor = CapabilityExecutor::new();
assert_eq!(executor.writes(), 0, "an executor that has run nothing has written nothing");
Source

pub fn cached_entries(&self) -> usize

How many entries the cache holds, all capabilities together.

Source

pub fn handler_invocations(&self) -> u64

How many handlers this executor has run — its cache misses and uncached calls, never another executor’s. Dropping the cache does not reset it.

use majordomus_cli::capability::executor::CapabilityExecutor;
let e = CapabilityExecutor::default();
assert_eq!(e.handler_invocations(), 0);
Source

pub fn cached(&self, ctx: &Context, id: &str, input: &Value) -> Option<Value>

The answer this executor holds for id asked with input in the repository ctx reads, when its cache has one that is still fresh, and None otherwise. No handler runs, nothing is stored, and a miss is not counted: it is how the latest reading of a source learns that the answer for a moved repository is already at hand (capability::readings).

use majordomus_cli::synthetic::SyntheticRepository;
use serde_json::json;

let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let describe = json!({ "id": "plan.status" });
// nothing is held before the capability was asked, and asking this way runs nothing
assert_eq!(ctx.executor.cached(&ctx, "capabilities.describe", &describe), None);
assert_eq!(ctx.executor.handler_invocations(), 0);
// once it was asked, what it answered is at hand
let answer = ctx.execute("capabilities.describe", describe.clone()).unwrap();
assert_eq!(ctx.executor.cached(&ctx, "capabilities.describe", &describe), Some(answer));
// a capability that does not exist holds nothing
assert_eq!(ctx.executor.cached(&ctx, "no.such.capability", &json!({})), None);
Source

pub fn readings_remembered(&self) -> usize

How many sources this executor remembers the latest reading of (capability::readings).

use majordomus_cli::capability::executor::CapabilityExecutor;
assert_eq!(CapabilityExecutor::new().readings_remembered(), 0);
Source

pub fn clear(&self)

Drop every cached entry.

Trait Implementations§

Source§

impl Debug for CapabilityExecutor

Source§

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

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

impl Default for CapabilityExecutor

Source§

fn default() -> CapabilityExecutor

Returns the “default value” for a type. 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
§

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> 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, 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