Skip to main content

Ctx

Struct Ctx 

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

Context threaded through every workflow and step.

Users never create or manage task IDs. The SDK handles everything via (parent_id, name) lookups — the unique constraint in the schema guarantees exactly-once step creation.

Implementations§

Source§

impl Ctx

Source

pub async fn start( db: &DatabaseConnection, name: &str, input: Option<Value>, ) -> Result<Self, DurableError>

Start or resume a root workflow by name.

let ctx = Ctx::start(&db, "ingest", json!({"crawl": "CC-2026"})).await?;
Source

pub async fn step<T, F, Fut>(&self, name: &str, f: F) -> Result<T, DurableError>
where T: Serialize + DeserializeOwned, F: FnOnce() -> Fut, Fut: Future<Output = Result<T, DurableError>>,

Run a step. If already completed, returns saved output. Otherwise executes the closure, saves the result, and returns it.

let count: u32 = ctx.step("fetch_count", || async { api.get_count().await }).await?;
Source

pub async fn child( &self, name: &str, input: Option<Value>, ) -> Result<Self, DurableError>

Start or resume a child workflow. Returns a new Ctx scoped to the child.

let child_ctx = ctx.child("embed_batch", json!({"vectors": 1000})).await?;
// use child_ctx.step(...) for steps inside the child
child_ctx.complete(json!({"done": true})).await?;
Source

pub async fn is_completed(&self) -> Result<bool, DurableError>

Check if this workflow/child was already completed (for skipping in parent).

Source

pub async fn get_output<T: DeserializeOwned>( &self, ) -> Result<Option<T>, DurableError>

Get the saved output if this task is completed.

Source

pub async fn complete<T: Serialize>( &self, output: &T, ) -> Result<(), DurableError>

Mark this workflow as completed with an output value.

Source

pub async fn fail(&self, error: &str) -> Result<(), DurableError>

Mark this workflow as failed.

Source

pub fn db(&self) -> &DatabaseConnection

Source

pub fn task_id(&self) -> Uuid

Source

pub fn next_sequence(&self) -> i32

Auto Trait Implementations§

§

impl !Freeze for Ctx

§

impl !RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl !UnwindSafe for Ctx

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> 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> 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.
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