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
- Starts in
ExecutionMode::Replayingif completed operations exist in history. - Starts in
ExecutionMode::Executingif history is empty or has no completed operations. - Transitions from
ReplayingtoExecutingwhen all completed operations have been visited viatrack_replay.
§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
impl ReplayEngine
Sourcepub fn new(
operations: HashMap<String, Operation>,
parent_id: Option<String>,
) -> Self
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 (Nonefor 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);Sourcepub fn check_result(&self, operation_id: &str) -> Option<&Operation>
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());Sourcepub fn track_replay(&mut self, operation_id: &str)
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");Sourcepub fn is_replaying(&self) -> bool
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());Sourcepub fn execution_mode(&self) -> ExecutionMode
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);Sourcepub fn generate_operation_id(&mut self) -> String
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);Sourcepub fn get_operation(&self, operation_id: &str) -> Option<&Operation>
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());Sourcepub fn operations(&self) -> &HashMap<String, Operation>
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());Sourcepub fn insert_operation(&mut self, id: String, operation: Operation)
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§
impl Freeze for ReplayEngine
impl RefUnwindSafe for ReplayEngine
impl Send for ReplayEngine
impl Sync for ReplayEngine
impl Unpin for ReplayEngine
impl UnsafeUnpin for ReplayEngine
impl UnwindSafe for ReplayEngine
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> 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