Skip to main content

RunRequest

Struct RunRequest 

Source
pub struct RunRequest<'a, K> { /* private fields */ }
Expand description

A run about to start — see Runtime::start.

The answer’s type follows the key. Unkeyed, a run answers with its RunOutcome and a spawn with its RunId; under once, with an Admission or a Spawned, because a key already held is answered by the run that holds it, and a caller must say what it does then.

ⓘ
let _: agentplane::runtime::RunOutcome = rt.start("c", input).once("k").run().await.unwrap();
ⓘ
rt.start("c", input).once("a").once("b");
let _: agentplane::runtime::RunOutcome = rt.start("c", input.clone()).run().await.unwrap();
let _: agentplane::runtime::Admission = rt.start("c", input).once("k").run().await.unwrap();

Implementations§

Source§

impl<K> RunRequest<'_, K>

Source

pub fn terms(self, terms: RunTerms) -> Self

Bind the run: a case, a caller’s chain, who asked, a pinned declaration. A second call replaces the first, as one value.

Source§

impl<'a> RunRequest<'a, Unkeyed>

Source

pub fn once(self, key: impl Into<String>) -> RunRequest<'a, Keyed>

Admit at most once per tenant under this key.

The door for an at-least-once emitter: a bus that retries until it sees a 2xx, a webhook fan-out, a queue with redelivery. The store claims the key in the same transaction that writes the run’s first record, so a second request under it cannot admit a second run — not on a retry, not across a restart, not from another instance sharing the store.

The key must carry its producer. An id is unique only within one emitter, so a bare message id lets two counterparties swallow each other’s messages as apparent retries. InboundEvent::dedup_key is the ready-made spelling.

Not the event buffer: an event nobody subscribes to is dead-lettered by sweep, so using the buffer as a ledger would spend that signal to buy deduplication.

Source

pub async fn run(self) -> Result<RunOutcome, RuntimeError>

Run, and wait until it rests.

§Errors

RuntimeError::NoProvider when no skill provides the capability, and whatever admission refuses — policy, quota, a halted tenant, an instance draining, a chain this plane may not act under.

Source

pub async fn spawn(self) -> Result<RunId, RuntimeError>

Admit, and let the run proceed in the background, returning its id.

Admission happens before this returns. The policy gate, the lease and the admission records are written first, so a refusal is an error here and not a task that never appears, and the id can be read at once. The run is durable: a process that dies mid-flight leaves a journal another instance resumes.

§Panics

Outside a Tokio runtime, as the rest of this crate’s timing does.

§Errors

As run.

Source§

impl RunRequest<'_, Keyed>

Source

pub async fn run(self) -> Result<Admission, RuntimeError>

Run under the key. A key already held comes back as Admission::Replayed or Admission::InFlight, not an error.

§Errors

As RunRequest::run, and RuntimeError::PlanContract for an empty key or one over MAX_ADMISSION_KEY_BYTES.

Source

pub async fn spawn(self) -> Result<Spawned, RuntimeError>

Spawn under the key. A key already held names its run, with fresh false.

§Panics

Outside a Tokio runtime.

§Errors

As run.

Source

pub async fn settle(self) -> Result<RunOutcome, RuntimeError>

Run under the key until the run it admitted rests, whoever admitted it, and answer with its outcome.

The shape a process that may have been killed mid-run wants on restart: the same request again. An unused key runs. A key whose run has rested answers with that run, its value re-derived by strict replay, which performs nothing. A key whose run is still working is resumed when nobody holds its lease — its holder has gone — and otherwise followed on the journal until it rests or its lease lapses.

§Errors

As run, and whatever resuming or replaying the held run refuses.

Trait Implementations§

Source§

impl<'a, K: Debug> Debug for RunRequest<'a, K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K> !RefUnwindSafe for RunRequest<'a, K>

§

impl<'a, K> !UnwindSafe for RunRequest<'a, K>

§

impl<'a, K> Freeze for RunRequest<'a, K>
where K: Freeze,

§

impl<'a, K> Send for RunRequest<'a, K>
where K: Send,

§

impl<'a, K> Sync for RunRequest<'a, K>
where K: Sync,

§

impl<'a, K> Unpin for RunRequest<'a, K>
where K: Unpin,

§

impl<'a, K> UnsafeUnpin for RunRequest<'a, K>
where K: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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 = !

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more