pub struct WorkflowClient<B> { /* private fields */ }Expand description
A client for submitting and controlling workflow instances.
Unlike CheckpointingRunner, the client does
not execute tasks — it only creates initial snapshots and stores
lifecycle signals. A PooledWorker (or
CheckpointingRunner::resume) picks up and executes the work.
§Example
use sayiir_runtime::WorkflowClient;
use sayiir_runtime::persistence::InMemoryBackend;
use sayiir_core::workflow::ConflictPolicy;
let backend = InMemoryBackend::new();
let client = WorkflowClient::new(backend)
.with_conflict_policy(ConflictPolicy::UseExisting);Implementations§
Source§impl<B> WorkflowClient<B>
impl<B> WorkflowClient<B>
Sourcepub fn new(backend: B) -> Self
pub fn new(backend: B) -> Self
Create a new client wrapping the given backend.
The default conflict policy is ConflictPolicy::Fail.
Create a client from a shared backend reference.
Useful when the same backend is shared with a runner or worker.
Sourcepub fn with_conflict_policy(self, policy: ConflictPolicy) -> Self
pub fn with_conflict_policy(self, policy: ConflictPolicy) -> Self
Set the conflict policy for duplicate instance IDs.
Source§impl<B> WorkflowClient<B>where
B: SnapshotStore + SignalStore,
impl<B> WorkflowClient<B>where
B: SnapshotStore + SignalStore,
Sourcepub async fn submit<C, Input, M>(
&self,
workflow: &Workflow<C, Input, M>,
instance_id: impl Into<String>,
input: Input,
) -> Result<(WorkflowStatus, Option<Bytes>), RuntimeError>where
Input: Send + 'static,
M: Send + Sync + 'static,
C: Codec + EnvelopeCodec + EncodeValue<Input> + 'static,
pub async fn submit<C, Input, M>(
&self,
workflow: &Workflow<C, Input, M>,
instance_id: impl Into<String>,
input: Input,
) -> Result<(WorkflowStatus, Option<Bytes>), RuntimeError>where
Input: Send + 'static,
M: Send + Sync + 'static,
C: Codec + EnvelopeCodec + EncodeValue<Input> + 'static,
Submit a workflow for execution.
Creates an initial snapshot in the backend so that a
PooledWorker can pick it up.
Does not execute any tasks.
Returns (WorkflowStatus, Option<Bytes>):
(InProgress, None)when a fresh snapshot was created.(status, output)when the conflict policy returns an existing instance.
§Errors
Returns RuntimeError::InstanceAlreadyExists when the policy is Fail
and the instance already exists, or propagates backend I/O errors.
Sourcepub async fn cancel(
&self,
instance_id: &str,
reason: Option<String>,
cancelled_by: Option<String>,
) -> Result<(), RuntimeError>
pub async fn cancel( &self, instance_id: &str, reason: Option<String>, cancelled_by: Option<String>, ) -> Result<(), RuntimeError>
Request cancellation of a workflow instance.
Stores a cancel signal in the backend. The worker picks it up at the next task boundary.
§Errors
Returns an error if the signal cannot be stored.
Sourcepub async fn pause(
&self,
instance_id: &str,
reason: Option<String>,
paused_by: Option<String>,
) -> Result<(), RuntimeError>
pub async fn pause( &self, instance_id: &str, reason: Option<String>, paused_by: Option<String>, ) -> Result<(), RuntimeError>
Request pausing of a workflow instance.
Stores a pause signal in the backend. The worker picks it up at the next task boundary.
§Errors
Returns an error if the signal cannot be stored.
Sourcepub async fn unpause(&self, instance_id: &str) -> Result<(), RuntimeError>
pub async fn unpause(&self, instance_id: &str) -> Result<(), RuntimeError>
Unpause a paused workflow instance.
§Errors
Returns an error if the workflow is not found or not paused.
Sourcepub async fn send_event(
&self,
instance_id: &str,
signal_name: &str,
payload: Bytes,
) -> Result<(), RuntimeError>
pub async fn send_event( &self, instance_id: &str, signal_name: &str, payload: Bytes, ) -> Result<(), RuntimeError>
Send an external event (signal) to a workflow instance.
The payload is buffered in FIFO order per (instance_id, signal_name).
§Errors
Returns an error if the event cannot be stored.
Sourcepub async fn status(
&self,
instance_id: &str,
) -> Result<WorkflowStatus, RuntimeError>
pub async fn status( &self, instance_id: &str, ) -> Result<WorkflowStatus, RuntimeError>
Get the current status of a workflow instance.
§Errors
Returns an error if the snapshot cannot be loaded.
Source§impl<B> WorkflowClient<B>
impl<B> WorkflowClient<B>
Sourcepub async fn get_task_result(
&self,
instance_id: &str,
task_id: &str,
) -> Result<Option<Bytes>, RuntimeError>
pub async fn get_task_result( &self, instance_id: &str, task_id: &str, ) -> Result<Option<Bytes>, RuntimeError>
Get a single task result from a workflow instance.
Returns Ok(Some(bytes)) if the task has completed, Ok(None) if the
task was never executed. For completed/failed workflows, the result is
recovered from the backend’s history or cache.
§Errors
Returns an error if the snapshot cannot be loaded.
Sourcepub async fn get_task_result_of<T: TaskIdentifier>(
&self,
instance_id: &str,
) -> Result<Option<Bytes>, RuntimeError>
pub async fn get_task_result_of<T: TaskIdentifier>( &self, instance_id: &str, ) -> Result<Option<Bytes>, RuntimeError>
Type-safe variant of get_task_result that
derives the task_id from a TaskIdentifier implementor (e.g. a
#[task]-generated struct).
let result = client.get_task_result_of::<ValidateOrderTask>("order-42").await?;§Errors
Returns an error if the snapshot cannot be loaded.
Auto Trait Implementations§
impl<B> Freeze for WorkflowClient<B>
impl<B> RefUnwindSafe for WorkflowClient<B>where
B: RefUnwindSafe,
impl<B> Send for WorkflowClient<B>
impl<B> Sync for WorkflowClient<B>
impl<B> Unpin for WorkflowClient<B>
impl<B> UnsafeUnpin for WorkflowClient<B>
impl<B> UnwindSafe for WorkflowClient<B>where
B: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.