Skip to main content

StepContext

Struct StepContext 

Source
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: String

The 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: String

The durable execution ARN

§attempt: u32

The 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

Source

pub fn new( operation_id: impl Into<String>, durable_execution_arn: impl Into<String>, ) -> Self

Creates a new StepContext.

Source

pub fn with_parent_id(self, parent_id: impl Into<String>) -> Self

Sets the parent ID.

Source

pub fn with_name(self, name: impl Into<String>) -> Self

Sets the name.

Source

pub fn with_attempt(self, attempt: u32) -> Self

Sets the attempt number.

Source

pub fn with_retry_payload(self, payload: impl Into<String>) -> Self

Sets the retry payload from the previous attempt. Requirements: 4.9

Source

pub fn serdes_context(&self) -> SerDesContext

Creates a SerDesContext from this StepContext.

Source

pub fn get_retry_payload<T>( &self, ) -> Result<Option<T>, Box<dyn Error + Send + Sync>>

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

Source§

fn clone(&self) -> StepContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StepContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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