Skip to main content

ReplayEngine

Struct ReplayEngine 

Source
pub struct ReplayEngine { /* private fields */ }
Expand description

Manage replay state for a durable execution.

The engine holds the complete operation state loaded from AWS, tracks which operations have been visited during the current invocation, and determines whether the execution is replaying cached results or executing new work.

§Replay Status Transitions

§Examples

use durable_lambda_core::replay::ReplayEngine;
use durable_lambda_core::types::ExecutionMode;
use std::collections::HashMap;

// Empty history → starts in Executing mode.
let engine = ReplayEngine::new(HashMap::new(), None);
assert_eq!(engine.execution_mode(), ExecutionMode::Executing);

Implementations§

Source§

impl ReplayEngine

Source

pub fn new( operations: HashMap<String, Operation>, parent_id: Option<String>, ) -> Self

Create a new replay engine from loaded operations.

Sets the initial ExecutionMode based on whether completed operations exist in the history. Operations with type Execution are excluded from replay tracking (they represent the root invocation, not user operations).

§Arguments
  • operations — All operations from the durable execution state, keyed by ID.
  • parent_id — Parent operation ID for child context scoping (None for root).
§Examples
use durable_lambda_core::replay::ReplayEngine;
use durable_lambda_core::types::ExecutionMode;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert_eq!(engine.execution_mode(), ExecutionMode::Executing);
Source

pub fn check_result(&self, operation_id: &str) -> Option<&Operation>

Look up an operation by ID, returning it if it exists with a completed status.

Returns None if the operation doesn’t exist or is not in a completed state.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert!(engine.check_result("nonexistent").is_none());
Source

pub fn track_replay(&mut self, operation_id: &str)

Mark an operation as visited and update replay status.

After visiting, checks whether all completed operations have been visited. If so, transitions the mode from ExecutionMode::Replaying to ExecutionMode::Executing.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let mut engine = ReplayEngine::new(HashMap::new(), None);
engine.track_replay("some-op-id");
Source

pub fn is_replaying(&self) -> bool

Return whether the engine is currently in replay mode.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert!(!engine.is_replaying());
Source

pub fn execution_mode(&self) -> ExecutionMode

Return the current execution mode.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use durable_lambda_core::types::ExecutionMode;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert_eq!(engine.execution_mode(), ExecutionMode::Executing);
Source

pub fn generate_operation_id(&mut self) -> String

Generate the next deterministic operation ID.

Delegates to the internal OperationIdGenerator.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let mut engine = ReplayEngine::new(HashMap::new(), None);
let id = engine.generate_operation_id();
assert_eq!(id.len(), 64);
Source

pub fn get_operation(&self, operation_id: &str) -> Option<&Operation>

Look up an operation by ID, returning it regardless of status.

Unlike check_result which only returns operations in a completed status, this returns the operation in any status (Started, Pending, Succeeded, etc.). Used by callback operations that need to extract the server-generated callback_id from operations that may still be in a non-completed state.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert!(engine.get_operation("nonexistent").is_none());
Source

pub fn operations(&self) -> &HashMap<String, Operation>

Return a reference to the operations map.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use std::collections::HashMap;

let engine = ReplayEngine::new(HashMap::new(), None);
assert!(engine.operations().is_empty());
Source

pub fn insert_operation(&mut self, id: String, operation: Operation)

Insert or update an operation in the state.

If the operation has a completed status (and is not the root Execution type), it is added to the completed set for replay tracking.

§Examples
use durable_lambda_core::replay::ReplayEngine;
use aws_sdk_lambda::types::{Operation, OperationType, OperationStatus};
use std::collections::HashMap;

let mut engine = ReplayEngine::new(HashMap::new(), None);
assert!(engine.operations().is_empty());

let op = Operation::builder()
    .id("op-1")
    .r#type(OperationType::Step)
    .status(OperationStatus::Succeeded)
    .start_timestamp(aws_smithy_types::DateTime::from_secs(0))
    .build()
    .unwrap();
engine.insert_operation("op-1".to_string(), op);
assert_eq!(engine.operations().len(), 1);

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> 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> Same for T

Source§

type Output = T

Should always be Self
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