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
impl BackgroundState
Sourcepub fn new() -> Self
pub fn new() -> Self
A state over a fresh InMemoryRunStore with no targets.
Sourcepub fn with_run_store(self, store: Arc<dyn DurableRunStore>) -> Self
pub fn with_run_store(self, store: Arc<dyn DurableRunStore>) -> Self
Uses store for runs; share one store across replicas.
Sourcepub fn with_executor(self, executor: Arc<dyn WorkflowExecutor>) -> Self
pub fn with_executor(self, executor: Arc<dyn WorkflowExecutor>) -> Self
Attaches the executor that resolves and runs workflows.
Sourcepub fn with_agent(self, target: impl Into<String>, runner: Arc<Runner>) -> Self
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.
Sourcepub fn with_app_name(self, app_name: impl Into<String>) -> Self
pub fn with_app_name(self, app_name: impl Into<String>) -> Self
Sets the app name workflow runs are recorded under. Defaults to background.
Sourcepub fn with_governance(self, control: GovernanceControl) -> Self
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.
Sourcepub fn with_worker_config(self, config: DurableWorkerConfig) -> Self
pub fn with_worker_config(self, config: DurableWorkerConfig) -> Self
Sets the embedded worker’s configuration, including the queue runs are enqueued on.
Sourcepub fn with_embedded_worker(self, enabled: bool) -> Self
pub fn with_embedded_worker(self, enabled: bool) -> Self
Whether this process runs a worker; disable it on API-only replicas.
Sourcepub fn run_store(&self) -> &Arc<dyn DurableRunStore> ⓘ
pub fn run_store(&self) -> &Arc<dyn DurableRunStore> ⓘ
The run store.
Sourcepub fn governance(&self) -> Option<GovernanceControl>
pub fn governance(&self) -> Option<GovernanceControl>
The governance control, if one is installed.
Sourcepub fn worker(&self) -> DurableWorker
pub fn worker(&self) -> DurableWorker
A DurableWorker over this state’s store, targets, governance, and configuration.
Sourcepub fn ensure_worker_started(&self)
pub fn ensure_worker_started(&self)
Starts the embedded worker once, when enabled and a Tokio runtime is running.
Sourcepub async fn wake_run(&self, run_id: &str) -> Result<(), AdkError>
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.
Sourcepub async fn wake_session_runs(
&self,
app_name: &str,
user_id: &str,
session_id: &str,
) -> Result<usize, AdkError>
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.
Sourcepub async fn shutdown_worker(&self)
pub async fn shutdown_worker(&self)
Stops the embedded worker, letting in-flight attempts finish.
Trait Implementations§
Source§impl Clone for BackgroundState
impl Clone for BackgroundState
Source§impl Debug for BackgroundState
impl Debug for BackgroundState
Auto Trait Implementations§
impl !RefUnwindSafe for BackgroundState
impl !UnwindSafe for BackgroundState
impl Forget for BackgroundState
impl Freeze for BackgroundStatewhere
*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 BackgroundStatewhere
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 BackgroundStatewhere
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 BackgroundStatewhere
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 BackgroundStatewhere
*const ArcInner<dyn DurableRunStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn DurableRunStore>>: UnsafeUnpin,
*const ArcInner<dyn WorkflowExecutor> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn WorkflowExecutor>>: UnsafeUnpin,
*const LeafNode<String, Arc<Runner>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Arc<Runner>)>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<RwLock<Option<GovernanceControl>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<Option<GovernanceControl>>>>: UnsafeUnpin,
*const LeafNode<AgentId, SetValZST> is !null: UnsafeUnpin,
PhantomData<Box<(AgentId, SetValZST)>>: UnsafeUnpin,
*const ArcInner<Mutex<Option<WorkerHandle>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<WorkerHandle>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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