pub struct WorkflowRegistry { /* private fields */ }Expand description
A WorkflowExecutor holding closures registered by name.
§Example
use adk_server::background::WorkflowRegistry;
use serde_json::json;
let registry = WorkflowRegistry::new()
.register("greet", |input, _cancel| async move {
Ok(json!({ "greeted": input.get("name").cloned() }))
})
.register_durable("settle", |_input, run| async move {
// A graph workflow would invoke its executor with `run.thread_id` here.
Ok(json!({ "thread": run.thread_id, "resumed": run.resumed }))
});Implementations§
Source§impl WorkflowRegistry
impl WorkflowRegistry
Sourcepub fn register<F, Fut>(
self,
workflow_id: impl Into<String>,
workflow: F,
) -> Selfwhere
F: Fn(WorkflowState, CancellationToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Value, String>> + Send + 'static,
pub fn register<F, Fut>(
self,
workflow_id: impl Into<String>,
workflow: F,
) -> Selfwhere
F: Fn(WorkflowState, CancellationToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Value, String>> + Send + 'static,
Registers workflow_id; a recovered run restarts it from its input.
Sourcepub fn register_durable<F, Fut>(
self,
workflow_id: impl Into<String>,
workflow: F,
) -> Selfwhere
F: Fn(WorkflowState, WorkflowRunContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Value, String>> + Send + 'static,
pub fn register_durable<F, Fut>(
self,
workflow_id: impl Into<String>,
workflow: F,
) -> Selfwhere
F: Fn(WorkflowState, WorkflowRunContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Value, String>> + Send + 'static,
Registers workflow_id with the attempt’s WorkflowRunContext, so a recovered
run can resume from its checkpoint thread.
Trait Implementations§
Source§impl Default for WorkflowRegistry
impl Default for WorkflowRegistry
Source§impl WorkflowExecutor for WorkflowRegistry
impl WorkflowExecutor for WorkflowRegistry
Source§fn has_workflow(&self, workflow_id: &str) -> bool
fn has_workflow(&self, workflow_id: &str) -> bool
Whether
workflow_id can be executed. Read moreSource§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
workflow_id: &'life1 str,
input: WorkflowState,
cancel_token: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
workflow_id: &'life1 str,
input: WorkflowState,
cancel_token: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn execute_durable<'life0, 'life1, 'async_trait>(
&'life0 self,
workflow_id: &'life1 str,
input: WorkflowState,
run: WorkflowRunContext,
) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_durable<'life0, 'life1, 'async_trait>(
&'life0 self,
workflow_id: &'life1 str,
input: WorkflowState,
run: WorkflowRunContext,
) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Run
workflow_id as one attempt of a durable run. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for WorkflowRegistry
impl !UnwindSafe for WorkflowRegistry
impl Forget for WorkflowRegistry
impl Freeze for WorkflowRegistry
impl Move for WorkflowRegistry
impl Send for WorkflowRegistry
impl Sync for WorkflowRegistry
impl Unpin for WorkflowRegistry
impl UnsafeUnpin for WorkflowRegistry
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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 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> ⓘ
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