Skip to main content

SerializableWorkflow

Struct SerializableWorkflow 

Source
pub struct SerializableWorkflow<C, Input, M = ()> { /* private fields */ }
Expand description

A workflow that can be serialized and deserialized.

This is a wrapper around Workflow that carries an internal TaskRegistry, automatically populated during building. This enables serialization without manually setting up a separate registry.

§Example

// Build a serializable workflow
let workflow = WorkflowBuilder::new(ctx)
    .with_registry()  // Enable serialization
    .then("step1", |i: u32| async move { Ok(i + 1) })
    .then("step2", |i: u32| async move { Ok(i * 2) })
    .build()?;

// Serialize
let serialized = workflow.to_serializable();
let json = serde_json::to_string(&serialized)?;

// Deserialize (uses internal registry)
let deserialized: SerializedWorkflowState = serde_json::from_str(&json)?;
let restored = workflow.to_runnable(&deserialized)?;

Implementations§

Source§

impl<C, Input, M> SerializableWorkflow<C, Input, M>

Source

pub fn workflow_id(&self) -> &str

Get the workflow ID.

Source

pub fn definition_hash(&self) -> &str

Get the definition hash.

Source

pub fn workflow(&self) -> &Workflow<C, Input, M>

Get a reference to the inner workflow.

Source

pub fn context(&self) -> &WorkflowContext<C, M>

Get a reference to the context.

Source

pub fn codec(&self) -> &Arc<C>

Get a reference to the codec.

Source

pub fn continuation(&self) -> &WorkflowContinuation

Get a reference to the continuation.

Source

pub fn metadata(&self) -> &Arc<M>

Get a reference to the metadata.

Source

pub fn registry(&self) -> &TaskRegistry

Get a reference to the internal task registry.

Source

pub fn to_serializable(&self) -> SerializedWorkflowState

Convert to a serializable state representation.

Returns a SerializedWorkflowState that includes the workflow ID, definition hash, and continuation structure. This can be serialized and later deserialized to resume the workflow.

Source

pub fn to_runnable( &self, state: &SerializedWorkflowState, ) -> Result<WorkflowContinuation, WorkflowError>

Convert a serialized workflow state to runnable using the internal registry.

§Errors

Returns WorkflowError::DefinitionMismatch if the definition hash doesn’t match this workflow’s hash, indicating the serialized state was created with a different workflow definition.

Returns WorkflowError::TaskNotFound if any task ID is not in the registry.

Auto Trait Implementations§

§

impl<C, Input, M> Freeze for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M = ()> !RefUnwindSafe for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M> Send for SerializableWorkflow<C, Input, M>
where Input: Send, C: Sync + Send, M: Sync + Send,

§

impl<C, Input, M> Sync for SerializableWorkflow<C, Input, M>
where Input: Sync, C: Sync + Send, M: Sync + Send,

§

impl<C, Input, M> Unpin for SerializableWorkflow<C, Input, M>
where Input: Unpin,

§

impl<C, Input, M> UnsafeUnpin for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M = ()> !UnwindSafe for SerializableWorkflow<C, Input, M>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.