pub struct DeterministicExecutor { /* private fields */ }Expand description
Handles deterministic operations for workflow execution.
Mirrors pynenc’s DeterministicExecutor. Ensures that operations like
random number generation, time functions, and UUIDs behave deterministically
across workflow replays by using deterministic seeds and storing results
in the state backend.
Implementations§
Source§impl DeterministicExecutor
impl DeterministicExecutor
Sourcepub fn new(
workflow_id: InvocationId,
state_backend: Arc<dyn StateBackend>,
) -> Self
pub fn new( workflow_id: InvocationId, state_backend: Arc<dyn StateBackend>, ) -> Self
Create a new deterministic executor for a workflow.
Sourcepub fn get_next_sequence(&mut self, operation: &str) -> u64
pub fn get_next_sequence(&mut self, operation: &str) -> u64
Get the next sequence number for an operation type.
Sourcepub fn get_operation_count(&self, operation: &str) -> u64
pub fn get_operation_count(&self, operation: &str) -> u64
Get the current count for an operation type.
Sourcepub async fn deterministic_operation<F>(
&mut self,
operation: &str,
generator: F,
) -> RustvelloResult<String>
pub async fn deterministic_operation<F>( &mut self, operation: &str, generator: F, ) -> RustvelloResult<String>
Execute an operation with deterministic results.
Checks if a value exists for this operation+sequence in the state backend. If found, returns the stored value (replay mode). Otherwise, generates a new value using the provided generator and stores it.
Sourcepub async fn get_base_time(&self) -> RustvelloResult<DateTime<Utc>>
pub async fn get_base_time(&self) -> RustvelloResult<DateTime<Utc>>
Get or establish the workflow base time for deterministic timestamps.
Sourcepub async fn random(&mut self) -> RustvelloResult<f64>
pub async fn random(&mut self) -> RustvelloResult<f64>
Generate a deterministic random number (0.0..1.0) using workflow-specific seed.
Sourcepub async fn utc_now(&mut self) -> RustvelloResult<DateTime<Utc>>
pub async fn utc_now(&mut self) -> RustvelloResult<DateTime<Utc>>
Get current time deterministically by advancing from base time.
Sourcepub async fn uuid(&mut self) -> RustvelloResult<String>
pub async fn uuid(&mut self) -> RustvelloResult<String>
Generate a deterministic UUID using workflow-specific seed.