Skip to main content

DurableContextOps

Trait DurableContextOps 

Source
pub trait DurableContextOps {
Show 26 methods // Required methods fn step<T, E, F, Fut>( &mut self, name: &str, f: F, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static; fn step_with_options<T, E, F, Fut>( &mut self, name: &str, options: StepOptions, f: F, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static; fn wait( &mut self, name: &str, duration_secs: i32, ) -> impl Future<Output = Result<(), DurableError>> + Send; fn create_callback( &mut self, name: &str, options: CallbackOptions, ) -> impl Future<Output = Result<CallbackHandle, DurableError>> + Send; fn invoke<T, P>( &mut self, name: &str, function_name: &str, payload: &P, ) -> impl Future<Output = Result<T, DurableError>> + Send where T: DeserializeOwned + Send, P: Serialize + Sync; fn parallel<T, F, Fut>( &mut self, name: &str, branches: Vec<F>, options: ParallelOptions, ) -> impl Future<Output = Result<BatchResult<T>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, F: FnOnce(DurableContext) -> Fut + Send + 'static, Fut: Future<Output = Result<T, DurableError>> + Send + 'static; fn child_context<T, F, Fut>( &mut self, name: &str, f: F, ) -> impl Future<Output = Result<T, DurableError>> + Send where T: Serialize + DeserializeOwned + Send, F: FnOnce(DurableContext) -> Fut + Send, Fut: Future<Output = Result<T, DurableError>> + Send; fn map<T, I, F, Fut>( &mut self, name: &str, items: Vec<I>, options: MapOptions, f: F, ) -> impl Future<Output = Result<BatchResult<T>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, I: Send + 'static, F: FnOnce(I, DurableContext) -> Fut + Send + 'static + Clone, Fut: Future<Output = Result<T, DurableError>> + Send + 'static; fn step_with_compensation<T, E, F, Fut, G, GFut>( &mut self, name: &str, forward_fn: F, compensate_fn: G, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static, G: FnOnce(T) -> GFut + Send + 'static, GFut: Future<Output = Result<(), DurableError>> + Send + 'static; fn step_with_compensation_opts<T, E, F, Fut, G, GFut>( &mut self, name: &str, options: StepOptions, forward_fn: F, compensate_fn: G, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static, G: FnOnce(T) -> GFut + Send + 'static, GFut: Future<Output = Result<(), DurableError>> + Send + 'static; fn run_compensations( &mut self, ) -> impl Future<Output = Result<CompensationResult, DurableError>> + Send; fn callback_result<T: DeserializeOwned>( &self, handle: &CallbackHandle, ) -> Result<T, DurableError>; fn execution_mode(&self) -> ExecutionMode; fn is_replaying(&self) -> bool; fn arn(&self) -> &str; fn checkpoint_token(&self) -> &str; fn log(&self, message: &str); fn log_with_data(&self, message: &str, data: &Value); fn log_debug(&self, message: &str); fn log_warn(&self, message: &str); fn log_error(&self, message: &str); fn log_debug_with_data(&self, message: &str, data: &Value); fn log_warn_with_data(&self, message: &str, data: &Value); fn log_error_with_data(&self, message: &str, data: &Value); fn enable_batch_mode(&mut self); fn flush_batch( &mut self, ) -> impl Future<Output = Result<(), DurableError>> + Send;
}
Expand description

Shared interface for all durable context types.

Every context type in the SDK implements this trait by delegating to the underlying DurableContext or its inherent methods. Use this trait as a generic bound when writing handler logic that should work across all context approaches (closure, trait, builder, or core directly).

§Static dispatch only

This trait uses native async (-> impl Future<...>) and is designed for static dispatch. Do not use dyn DurableContextOps — there is no object-safe version.

§Examples

use durable_lambda_core::DurableContextOps;
use durable_lambda_core::error::DurableError;

async fn process_order<C: DurableContextOps>(ctx: &mut C, order_id: u64) -> Result<(), DurableError> {
    let _result: Result<String, String> = ctx.step("validate", move || async move {
        Ok(format!("validated:{order_id}"))
    }).await?;
    ctx.log("order processed");
    Ok(())
}

Required Methods§

Source

fn step<T, E, F, Fut>( &mut self, name: &str, f: F, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,

Execute a named step with checkpointing.

See DurableContext::step for full documentation.

Source

fn step_with_options<T, E, F, Fut>( &mut self, name: &str, options: StepOptions, f: F, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,

Execute a named step with checkpointing and retry configuration.

See DurableContext::step_with_options for full documentation.

Source

fn wait( &mut self, name: &str, duration_secs: i32, ) -> impl Future<Output = Result<(), DurableError>> + Send

Suspend execution for the specified duration.

See DurableContext::wait for full documentation.

Source

fn create_callback( &mut self, name: &str, options: CallbackOptions, ) -> impl Future<Output = Result<CallbackHandle, DurableError>> + Send

Register a callback and return a handle with the server-generated callback ID.

See DurableContext::create_callback for full documentation.

Source

fn invoke<T, P>( &mut self, name: &str, function_name: &str, payload: &P, ) -> impl Future<Output = Result<T, DurableError>> + Send

Durably invoke another Lambda function and return its result.

See DurableContext::invoke for full documentation.

Source

fn parallel<T, F, Fut>( &mut self, name: &str, branches: Vec<F>, options: ParallelOptions, ) -> impl Future<Output = Result<BatchResult<T>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, F: FnOnce(DurableContext) -> Fut + Send + 'static, Fut: Future<Output = Result<T, DurableError>> + Send + 'static,

Execute multiple branches concurrently and return their results.

See DurableContext::parallel for full documentation.

Source

fn child_context<T, F, Fut>( &mut self, name: &str, f: F, ) -> impl Future<Output = Result<T, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send, F: FnOnce(DurableContext) -> Fut + Send, Fut: Future<Output = Result<T, DurableError>> + Send,

Execute an isolated subflow with its own checkpoint namespace.

See DurableContext::child_context for full documentation.

Source

fn map<T, I, F, Fut>( &mut self, name: &str, items: Vec<I>, options: MapOptions, f: F, ) -> impl Future<Output = Result<BatchResult<T>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, I: Send + 'static, F: FnOnce(I, DurableContext) -> Fut + Send + 'static + Clone, Fut: Future<Output = Result<T, DurableError>> + Send + 'static,

Process a collection of items in parallel and return their results.

See DurableContext::map for full documentation.

Source

fn step_with_compensation<T, E, F, Fut, G, GFut>( &mut self, name: &str, forward_fn: F, compensate_fn: G, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static, G: FnOnce(T) -> GFut + Send + 'static, GFut: Future<Output = Result<(), DurableError>> + Send + 'static,

Execute a forward step and register a compensation closure on success.

See DurableContext::step_with_compensation for full documentation.

Source

fn step_with_compensation_opts<T, E, F, Fut, G, GFut>( &mut self, name: &str, options: StepOptions, forward_fn: F, compensate_fn: G, ) -> impl Future<Output = Result<Result<T, E>, DurableError>> + Send
where T: Serialize + DeserializeOwned + Send + 'static, E: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static, G: FnOnce(T) -> GFut + Send + 'static, GFut: Future<Output = Result<(), DurableError>> + Send + 'static,

Execute a forward step (with options) and register a compensation closure on success.

See DurableContext::step_with_compensation_opts for full documentation.

Source

fn run_compensations( &mut self, ) -> impl Future<Output = Result<CompensationResult, DurableError>> + Send

Execute all registered compensations in reverse registration order.

See DurableContext::run_compensations for full documentation.

Source

fn callback_result<T: DeserializeOwned>( &self, handle: &CallbackHandle, ) -> Result<T, DurableError>

Check the result of a previously created callback.

See DurableContext::callback_result for full documentation.

Source

fn execution_mode(&self) -> ExecutionMode

Return the current execution mode (Replaying or Executing).

Source

fn is_replaying(&self) -> bool

Return whether the context is currently replaying from history.

Source

fn arn(&self) -> &str

Return a reference to the durable execution ARN.

Source

fn checkpoint_token(&self) -> &str

Return the current checkpoint token.

Source

fn log(&self, message: &str)

Emit a replay-safe info-level log message.

Source

fn log_with_data(&self, message: &str, data: &Value)

Emit a replay-safe info-level log message with structured data.

Source

fn log_debug(&self, message: &str)

Emit a replay-safe debug-level log message.

Source

fn log_warn(&self, message: &str)

Emit a replay-safe warn-level log message.

Source

fn log_error(&self, message: &str)

Emit a replay-safe error-level log message.

Source

fn log_debug_with_data(&self, message: &str, data: &Value)

Emit a replay-safe debug-level log message with structured data.

Source

fn log_warn_with_data(&self, message: &str, data: &Value)

Emit a replay-safe warn-level log message with structured data.

Source

fn log_error_with_data(&self, message: &str, data: &Value)

Emit a replay-safe error-level log message with structured data.

Source

fn enable_batch_mode(&mut self)

Enable batch checkpoint mode.

See DurableContext::enable_batch_mode for full documentation.

Source

fn flush_batch( &mut self, ) -> impl Future<Output = Result<(), DurableError>> + Send

Flush accumulated batch checkpoint updates.

See DurableContext::flush_batch for full documentation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§