pub struct DurableInstance { /* private fields */ }Expand description
Handle returned by init / init_with_config.
Wraps a database connection, the executor identity, and any tasks
recovered from prior crashes. Implements Deref<Target = DatabaseConnection>
so it can be passed anywhere a &DatabaseConnection is expected.
ⓘ
let durable = durable::init("postgres://localhost/mydb").await?;
// Use as &DatabaseConnection (via Deref)
let ctx = Ctx::start(&durable, "my_wf", None).await?;
// Or start with executor tracking for proper crash recovery
let ctx = durable.start_workflow("my_wf", None).await?;
// Inspect tasks recovered on startup
for task in durable.recovered() {
println!("recovered: {} ({})", task.name, task.id);
}Implementations§
Source§impl DurableInstance
impl DurableInstance
Sourcepub fn db(&self) -> &DatabaseConnection
pub fn db(&self) -> &DatabaseConnection
The underlying database connection.
Sourcepub fn executor_id(&self) -> &str
pub fn executor_id(&self) -> &str
The unique executor ID for this process.
Sourcepub fn recovered(&self) -> &[RecoveredTask]
pub fn recovered(&self) -> &[RecoveredTask]
Tasks recovered from prior crashes during init.
Each entry was reset from RUNNING to PENDING. To resume a recovered
workflow, call Ctx::from_id with the task’s id.
Sourcepub async fn start_workflow(
&self,
name: &str,
input: Option<Value>,
) -> Result<Ctx, DurableError>
pub async fn start_workflow( &self, name: &str, input: Option<Value>, ) -> Result<Ctx, DurableError>
Start a new root workflow, tagging it with this instance’s executor_id so heartbeat-based recovery works if this process crashes.
Sourcepub async fn start_workflow_with_timeout(
&self,
name: &str,
input: Option<Value>,
timeout_ms: i64,
) -> Result<Ctx, DurableError>
pub async fn start_workflow_with_timeout( &self, name: &str, input: Option<Value>, timeout_ms: i64, ) -> Result<Ctx, DurableError>
Start a new root workflow with a timeout, tagging it with this instance’s executor_id.
Methods from Deref<Target = DatabaseConnection>§
Trait Implementations§
Source§impl Deref for DurableInstance
impl Deref for DurableInstance
Source§type Target = DatabaseConnection
type Target = DatabaseConnection
The resulting type after dereferencing.
Source§fn deref(&self) -> &DatabaseConnection
fn deref(&self) -> &DatabaseConnection
Dereferences the value.
Auto Trait Implementations§
impl Freeze for DurableInstance
impl !RefUnwindSafe for DurableInstance
impl Send for DurableInstance
impl Sync for DurableInstance
impl Unpin for DurableInstance
impl UnsafeUnpin for DurableInstance
impl !UnwindSafe for DurableInstance
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