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
impl Ctx
Sourcepub async fn start(
db: &DatabaseConnection,
name: &str,
input: Option<Value>,
) -> Result<Self, DurableError>
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?;Sourcepub 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>>,
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?;Sourcepub async fn child(
&self,
name: &str,
input: Option<Value>,
) -> Result<Self, DurableError>
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?;Sourcepub async fn is_completed(&self) -> Result<bool, DurableError>
pub async fn is_completed(&self) -> Result<bool, DurableError>
Check if this workflow/child was already completed (for skipping in parent).
Sourcepub async fn get_output<T: DeserializeOwned>(
&self,
) -> Result<Option<T>, DurableError>
pub async fn get_output<T: DeserializeOwned>( &self, ) -> Result<Option<T>, DurableError>
Get the saved output if this task is completed.
Sourcepub async fn complete<T: Serialize>(
&self,
output: &T,
) -> Result<(), DurableError>
pub async fn complete<T: Serialize>( &self, output: &T, ) -> Result<(), DurableError>
Mark this workflow as completed with an output value.
Sourcepub async fn fail(&self, error: &str) -> Result<(), DurableError>
pub async fn fail(&self, error: &str) -> Result<(), DurableError>
Mark this workflow as failed.
pub fn db(&self) -> &DatabaseConnection
pub fn task_id(&self) -> Uuid
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> 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
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