Skip to main content

BackgroundState

Struct BackgroundState 

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

Shared state for the background run endpoints, and the embedded worker.

Holds the run store (in memory by default), the targets runs execute, and the governance control. Unless disabled with with_embedded_worker(false), a DurableWorker over the same store and targets starts in this process the first time the server is built inside a Tokio runtime or a run is submitted.

Implementations§

Source§

impl BackgroundState

Source

pub fn new() -> Self

A state over a fresh InMemoryRunStore with no targets.

Source

pub fn with_run_store(self, store: Arc<dyn DurableRunStore>) -> Self

Uses store for runs; share one store across replicas.

Source

pub fn with_executor(self, executor: Arc<dyn WorkflowExecutor>) -> Self

Attaches the executor that resolves and runs workflows.

Source

pub fn with_agent(self, target: impl Into<String>, runner: Arc<Runner>) -> Self

Runs whose target is target execute through runner, in the runner’s app.

Source

pub fn with_app_name(self, app_name: impl Into<String>) -> Self

Sets the app name workflow runs are recorded under. Defaults to background.

Source

pub fn with_governance(self, control: GovernanceControl) -> Self

Refuses submissions, and stops the embedded worker claiming, while control refuses work. ServerBuilder installs ServerConfig::governance when none is set.

Source

pub fn with_worker_config(self, config: DurableWorkerConfig) -> Self

Sets the embedded worker’s configuration, including the queue runs are enqueued on.

Source

pub fn with_embedded_worker(self, enabled: bool) -> Self

Whether this process runs a worker; disable it on API-only replicas.

Source

pub fn run_store(&self) -> &Arc<dyn DurableRunStore> ⓘ

The run store.

Source

pub fn governance(&self) -> Option<GovernanceControl>

The governance control, if one is installed.

Source

pub fn worker(&self) -> DurableWorker

A DurableWorker over this state’s store, targets, governance, and configuration.

Source

pub fn ensure_worker_started(&self)

Starts the embedded worker once, when enabled and a Tokio runtime is running.

Source

pub async fn wake_run(&self, run_id: &str) -> Result<(), AdkError>

Makes a parked run claimable now, for the approval service to call once it records a decision for the run’s held tool call.

A waiting run is claimed again at once and resumes its session, so the agent dispatches the held call through the governed path with the decision. A wake that arrives while the run is still running is kept and applied when it parks.

§Errors

Returns run_store.not_found for an unknown run, or the store’s error.

Source

pub async fn wake_session_runs( &self, app_name: &str, user_id: &str, session_id: &str, ) -> Result<usize, AdkError>

Wakes every parked run of app_name continuing session_id for user_id, and returns how many were woken; for an approval service that knows the decision’s session but not its run.

§Errors

Returns the store’s error.

Source

pub async fn shutdown_worker(&self)

Stops the embedded worker, letting in-flight attempts finish.

Trait Implementations§

Source§

impl Clone for BackgroundState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BackgroundState

Source§

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

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

impl Default for BackgroundState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for BackgroundState

§

impl !UnwindSafe for BackgroundState

§

impl Forget for BackgroundState

§

impl Freeze for BackgroundState
where *const ArcInner<dyn DurableRunStore> is !null: Freeze, PhantomData<ArcInner<dyn DurableRunStore>>: Freeze, *const ArcInner<dyn WorkflowExecutor> is !null: Freeze, PhantomData<ArcInner<dyn WorkflowExecutor>>: Freeze, *const LeafNode<String, Arc<Runner>> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Arc<Runner>)>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<RwLock<Option<GovernanceControl>>> is !null: Freeze, PhantomData<ArcInner<RwLock<Option<GovernanceControl>>>>: Freeze, *const LeafNode<AgentId, SetValZST> is !null: Freeze, PhantomData<Box<(AgentId, SetValZST)>>: Freeze, *const ArcInner<Mutex<Option<WorkerHandle>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Option<WorkerHandle>>>>: Freeze,

§

impl Move for BackgroundState

§

impl Send for BackgroundState
where Arc<dyn DurableRunStore>: Send, Arc<dyn WorkflowExecutor>: Send, NodeRef<Owned, String, Arc<Runner>, LeafOrInternal>: Send, BoxRaw<(String, Arc<Runner>)>: Send, RawVecInner: Send, Arc<RwLock<Option<GovernanceControl>>>: Send, NodeRef<Owned, AgentId, SetValZST, LeafOrInternal>: Send, BoxRaw<(AgentId, SetValZST)>: Send, Arc<Mutex<Option<WorkerHandle>>>: Send,

§

impl Sync for BackgroundState
where Arc<dyn DurableRunStore>: Sync, Arc<dyn WorkflowExecutor>: Sync, NodeRef<Owned, String, Arc<Runner>, LeafOrInternal>: Sync, BoxRaw<(String, Arc<Runner>)>: Sync, RawVecInner: Sync, Arc<RwLock<Option<GovernanceControl>>>: Sync, NodeRef<Owned, AgentId, SetValZST, LeafOrInternal>: Sync, BoxRaw<(AgentId, SetValZST)>: Sync, Arc<Mutex<Option<WorkerHandle>>>: Sync,

§

impl Unpin for BackgroundState
where Arc<dyn DurableRunStore>: Unpin, Arc<dyn WorkflowExecutor>: Unpin, *const LeafNode<String, Arc<Runner>> is !null: Unpin, Box<(String, Arc<Runner>)>: Unpin, *const u8 is !null: Unpin, Arc<RwLock<Option<GovernanceControl>>>: Unpin, *const LeafNode<AgentId, SetValZST> is !null: Unpin, Box<(AgentId, SetValZST)>: Unpin, Arc<Mutex<Option<WorkerHandle>>>: Unpin,

§

impl UnsafeUnpin for BackgroundState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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<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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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