pub struct OperationHandle { /* private fields */ }Expand description
A lazy handle to an operation that will be populated during execution.
Registered before run() via get_operation_handle(), get_operation_handle_by_index(),
or get_operation_handle_by_id() on the LocalDurableTestRunner. The handle starts
unpopulated and is filled with operation data when the orchestrator finds a matching
operation during execution.
§Examples
use durable_execution_sdk_testing::OperationHandle;
// Pre-register a handle before run()
let handle = runner.get_operation_handle("my-callback");
// Start non-blocking execution
let future = runner.run(input);
// Wait for the operation to reach Submitted status
handle.wait_for_data(WaitingOperationStatus::Submitted).await?;
// Send callback response
handle.send_callback_success("result").await?;
// Await the final result
let result = future.await?;Implementations§
Source§impl OperationHandle
impl OperationHandle
Sourcepub fn new(
matcher: OperationMatcher,
all_operations: Arc<RwLock<Vec<Operation>>>,
) -> Self
pub fn new( matcher: OperationMatcher, all_operations: Arc<RwLock<Vec<Operation>>>, ) -> Self
Creates a new unpopulated OperationHandle with the given matcher.
The handle starts with no operation data. It will be populated during execution when the orchestrator finds an operation matching the matcher.
§Arguments
matcher- How this handle should match against operationsall_operations- Shared reference to all operations for child enumeration
Sourcepub async fn get_id(&self) -> Result<String, TestError>
pub async fn get_id(&self) -> Result<String, TestError>
Gets the operation ID.
§Returns
Ok(String)- The operation ID if the handle is populatedErr(TestError::OperationNotFound)- If the handle is not yet populated
Sourcepub async fn get_name(&self) -> Result<Option<String>, TestError>
pub async fn get_name(&self) -> Result<Option<String>, TestError>
Gets the operation name.
§Returns
Ok(Option<String>)- The operation name if the handle is populatedErr(TestError::OperationNotFound)- If the handle is not yet populated
Sourcepub async fn get_type(&self) -> Result<OperationType, TestError>
pub async fn get_type(&self) -> Result<OperationType, TestError>
Gets the operation type.
§Returns
Ok(OperationType)- The operation type if the handle is populatedErr(TestError::OperationNotFound)- If the handle is not yet populated
Sourcepub async fn get_status(&self) -> Result<OperationStatus, TestError>
pub async fn get_status(&self) -> Result<OperationStatus, TestError>
Gets the operation status.
§Returns
Ok(OperationStatus)- The operation status if the handle is populatedErr(TestError::OperationNotFound)- If the handle is not yet populated
Sourcepub async fn get_step_details<T: DeserializeOwned>(
&self,
) -> Result<StepDetails<T>, TestError>
pub async fn get_step_details<T: DeserializeOwned>( &self, ) -> Result<StepDetails<T>, TestError>
Sourcepub async fn get_callback_details<T: DeserializeOwned>(
&self,
) -> Result<CallbackDetails<T>, TestError>
pub async fn get_callback_details<T: DeserializeOwned>( &self, ) -> Result<CallbackDetails<T>, TestError>
Sourcepub async fn get_wait_details(&self) -> Result<WaitDetails, TestError>
pub async fn get_wait_details(&self) -> Result<WaitDetails, TestError>
Gets wait-specific details.
§Returns
Ok(WaitDetails)- The wait details if populated and is a Wait operationErr(TestError)- If unpopulated or wrong operation type
Sourcepub async fn get_invoke_details<T: DeserializeOwned>(
&self,
) -> Result<InvokeDetails<T>, TestError>
pub async fn get_invoke_details<T: DeserializeOwned>( &self, ) -> Result<InvokeDetails<T>, TestError>
Sourcepub async fn get_context_details<T: DeserializeOwned>(
&self,
) -> Result<ContextDetails<T>, TestError>
pub async fn get_context_details<T: DeserializeOwned>( &self, ) -> Result<ContextDetails<T>, TestError>
Sourcepub async fn is_populated(&self) -> bool
pub async fn is_populated(&self) -> bool
Checks if the handle has been populated with operation data.
§Returns
true if the handle has been populated, false otherwise.
Sourcepub async fn wait_for_data(
&self,
status: WaitingOperationStatus,
) -> Result<(), TestError>
pub async fn wait_for_data( &self, status: WaitingOperationStatus, ) -> Result<(), TestError>
Waits for the operation to reach the specified WaitingOperationStatus.
Resolves immediately if the operation has already reached the target status.
If the watch channel closes (execution ended) before the target status is
reached, returns Err(TestError::ExecutionCompletedEarly(...)).
§Arguments
status- The target status to wait for
§Returns
Ok(())- When the operation reaches the target statusErr(TestError::ExecutionCompletedEarly)- If execution ends before reaching the target
§Examples
// Wait for a callback to be ready for responses
handle.wait_for_data(WaitingOperationStatus::Submitted).await?;
// Wait for an operation to complete
handle.wait_for_data(WaitingOperationStatus::Completed).await?;Sourcepub async fn send_callback_success(&self, result: &str) -> Result<(), TestError>
pub async fn send_callback_success(&self, result: &str) -> Result<(), TestError>
Sends a success response for a callback operation.
Validates that the handle is populated, the operation is a callback type, and the callback_id is available (Submitted status) before delegating to the callback sender.
§Arguments
result- The result value to send as a JSON string
§Returns
Ok(())- If the callback response was sent successfullyErr(TestError::OperationNotFound)- If the handle is not yet populatedErr(TestError::NotCallbackOperation)- If the operation is not a callbackErr(TestError::ResultNotAvailable)- If the callback_id is not yet available
Sourcepub async fn send_callback_failure(
&self,
error: &TestResultError,
) -> Result<(), TestError>
pub async fn send_callback_failure( &self, error: &TestResultError, ) -> Result<(), TestError>
Sends a failure response for a callback operation.
Validates that the handle is populated, the operation is a callback type, and the callback_id is available (Submitted status) before delegating to the callback sender.
§Arguments
error- The error information to send
§Returns
Ok(())- If the callback failure was sent successfullyErr(TestError::OperationNotFound)- If the handle is not yet populatedErr(TestError::NotCallbackOperation)- If the operation is not a callbackErr(TestError::ResultNotAvailable)- If the callback_id is not yet available
Sourcepub async fn send_callback_heartbeat(&self) -> Result<(), TestError>
pub async fn send_callback_heartbeat(&self) -> Result<(), TestError>
Sends a heartbeat for a callback operation.
Validates that the handle is populated, the operation is a callback type, and the callback_id is available (Submitted status) before delegating to the callback sender.
§Returns
Ok(())- If the heartbeat was sent successfullyErr(TestError::OperationNotFound)- If the handle is not yet populatedErr(TestError::NotCallbackOperation)- If the operation is not a callbackErr(TestError::ResultNotAvailable)- If the callback_id is not yet available
Sourcepub async fn get_child_operations(
&self,
) -> Result<Vec<DurableOperation>, TestError>
pub async fn get_child_operations( &self, ) -> Result<Vec<DurableOperation>, TestError>
Returns all child operations nested under this operation.
Child operations are those whose parent_id matches this operation’s id.
The returned operations preserve execution order (same order as in the
shared operations list).
§Returns
Ok(Vec<DurableOperation>)- Child operations if the handle is populatedErr(TestError::OperationNotFound)- If the handle is not yet populated
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OperationHandle
impl !RefUnwindSafe for OperationHandle
impl Send for OperationHandle
impl Sync for OperationHandle
impl Unpin for OperationHandle
impl UnsafeUnpin for OperationHandle
impl !UnwindSafe for OperationHandle
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