pub struct CapabilityExecutor { /* private fields */ }Expand description
The executor of one registry.
Implementations§
Source§impl CapabilityExecutor
impl CapabilityExecutor
Sourcepub fn execute(
&self,
ctx: &Context,
id: &str,
input: Value,
) -> Result<Value, CapabilityError>
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.
Sourcepub fn execute_uncached(
&self,
ctx: &Context,
id: &str,
input: Value,
) -> Result<Value, CapabilityError>
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.
Sourcepub fn writes(&self) -> u64
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");Sourcepub fn cached_entries(&self) -> usize
pub fn cached_entries(&self) -> usize
How many entries the cache holds, all capabilities together.
Sourcepub fn handler_invocations(&self) -> u64
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);Sourcepub fn cached(&self, ctx: &Context, id: &str, input: &Value) -> Option<Value>
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);Sourcepub fn readings_remembered(&self) -> usize
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);