pub struct StepContext {
pub operation_id: String,
pub parent_id: Option<String>,
pub name: Option<String>,
pub durable_execution_arn: String,
pub attempt: u32,
pub retry_payload: Option<String>,
}Expand description
Context provided to step functions during execution.
This struct provides information about the current step execution that can be used by the step function for logging or other purposes.
§Examples
Creating a basic step context:
use durable_execution_sdk::handlers::StepContext;
let ctx = StepContext::new("op-123", "arn:aws:lambda:us-east-1:123456789012:function:test:durable:abc");
assert_eq!(ctx.operation_id, "op-123");
assert_eq!(ctx.attempt, 0);
assert!(ctx.parent_id.is_none());Using the builder pattern:
use durable_execution_sdk::handlers::StepContext;
let ctx = StepContext::new("op-123", "arn:aws:lambda:us-east-1:123456789012:function:test:durable:abc")
.with_parent_id("parent-456")
.with_name("process-order")
.with_attempt(2);
assert_eq!(ctx.parent_id, Some("parent-456".to_string()));
assert_eq!(ctx.name, Some("process-order".to_string()));
assert_eq!(ctx.attempt, 2);Fields§
§operation_id: StringThe operation identifier for this step
parent_id: Option<String>The parent operation ID, if any
name: Option<String>The name of the step, if provided
durable_execution_arn: StringThe durable execution ARN
attempt: u32The current retry attempt (0-indexed) Requirements: 4.8
retry_payload: Option<String>The retry payload from the previous attempt (for wait-for-condition pattern) Requirements: 4.9
Implementations§
Source§impl StepContext
impl StepContext
Sourcepub fn new(
operation_id: impl Into<String>,
durable_execution_arn: impl Into<String>,
) -> Self
pub fn new( operation_id: impl Into<String>, durable_execution_arn: impl Into<String>, ) -> Self
Creates a new StepContext.
Sourcepub fn with_parent_id(self, parent_id: impl Into<String>) -> Self
pub fn with_parent_id(self, parent_id: impl Into<String>) -> Self
Sets the parent ID.
Sourcepub fn with_attempt(self, attempt: u32) -> Self
pub fn with_attempt(self, attempt: u32) -> Self
Sets the attempt number.
Sourcepub fn with_retry_payload(self, payload: impl Into<String>) -> Self
pub fn with_retry_payload(self, payload: impl Into<String>) -> Self
Sets the retry payload from the previous attempt. Requirements: 4.9
Sourcepub fn serdes_context(&self) -> SerDesContext
pub fn serdes_context(&self) -> SerDesContext
Creates a SerDesContext from this StepContext.
Sourcepub fn get_retry_payload<T>(
&self,
) -> Result<Option<T>, Box<dyn Error + Send + Sync>>where
T: DeserializeOwned,
pub fn get_retry_payload<T>(
&self,
) -> Result<Option<T>, Box<dyn Error + Send + Sync>>where
T: DeserializeOwned,
Returns the retry payload deserialized to the specified type.
This is useful for the wait-for-condition pattern where state is passed between retry attempts.
§Type Parameters
T- The type to deserialize the payload into
§Returns
Ok(Some(T)) if payload exists and can be deserialized,
Ok(None) if no payload exists,
Err if deserialization fails.
§Examples
use durable_execution_sdk::handlers::StepContext;
use serde::Deserialize;
#[derive(Deserialize, Debug, PartialEq)]
struct RetryState {
counter: i32,
}
// With a payload
let ctx = StepContext::new("op-123", "arn:test")
.with_retry_payload(r#"{"counter": 5}"#);
let state: Option<RetryState> = ctx.get_retry_payload().unwrap();
assert_eq!(state, Some(RetryState { counter: 5 }));
// Without a payload
let ctx_no_payload = StepContext::new("op-456", "arn:test");
let state: Option<RetryState> = ctx_no_payload.get_retry_payload().unwrap();
assert!(state.is_none());Trait Implementations§
Source§impl Clone for StepContext
impl Clone for StepContext
Source§fn clone(&self) -> StepContext
fn clone(&self) -> StepContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StepContext
impl RefUnwindSafe for StepContext
impl Send for StepContext
impl Sync for StepContext
impl Unpin for StepContext
impl UnsafeUnpin for StepContext
impl UnwindSafe for StepContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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