pub struct ToolTimeoutManager { /* private fields */ }Expand description
Tool timeout and cancellation manager
Manages per-tool timeout policies and provides cancellation-safe timeout enforcement for tool execution with comprehensive audit logging.
Implementations§
Source§impl ToolTimeoutManager
impl ToolTimeoutManager
Sourcepub fn new(config: TimeoutConfig, metrics: Arc<ServerMetrics>) -> Self
pub fn new(config: TimeoutConfig, metrics: Arc<ServerMetrics>) -> Self
Create a new timeout manager with the given configuration and metrics
Sourcepub fn get_tool_timeout(&self, tool_name: &str) -> Duration
pub fn get_tool_timeout(&self, tool_name: &str) -> Duration
Get the timeout duration for a specific tool
Returns per-tool override if configured, otherwise returns default timeout.
Sourcepub async fn execute_with_timeout_and_cancellation<F, T>(
&self,
tool_name: &str,
operation: F,
) -> Result<(T, CancellationToken), ToolTimeoutError>
pub async fn execute_with_timeout_and_cancellation<F, T>( &self, tool_name: &str, operation: F, ) -> Result<(T, CancellationToken), ToolTimeoutError>
Execute a tool with timeout and cooperative cancellation support
This is the primary method for executing tools with comprehensive timeout and cancellation handling following Tokio best practices.
Returns both the result and the cancellation token for context propagation.
Sourcepub async fn execute_with_external_token<F, T>(
&self,
tool_name: &str,
operation: F,
cancellation_token: CancellationToken,
) -> Result<T, ToolTimeoutError>
pub async fn execute_with_external_token<F, T>( &self, tool_name: &str, operation: F, cancellation_token: CancellationToken, ) -> Result<T, ToolTimeoutError>
Execute a tool with a provided cancellation token
This method allows external code to provide the cancellation token, enabling tight integration with RequestContext and other systems.
Sourcepub async fn execute_with_timeout<F, T>(
&self,
tool_name: &str,
operation: F,
) -> Result<T, ToolTimeoutError>
pub async fn execute_with_timeout<F, T>( &self, tool_name: &str, operation: F, ) -> Result<T, ToolTimeoutError>
Execute a tool with timeout (backward compatible API)
This method provides backward compatibility for existing code that doesn’t
need access to the cancellation token. New code should use
execute_with_timeout_and_cancellation for cooperative cancellation support.
Sourcepub async fn get_active_executions(&self) -> Vec<ActiveExecutionInfo>
pub async fn get_active_executions(&self) -> Vec<ActiveExecutionInfo>
Get statistics about active tool executions
Returns information about currently running tools for monitoring and debugging purposes.
Sourcepub async fn cancel_all_executions(&self)
pub async fn cancel_all_executions(&self)
Cancel all active executions (for graceful shutdown)
Signals cooperative cancellation to all active tool executions. Tools that check their cancellation tokens will receive the signal and can perform graceful cleanup before terminating.
Trait Implementations§
Source§impl Clone for ToolTimeoutManager
impl Clone for ToolTimeoutManager
Source§fn clone(&self) -> ToolTimeoutManager
fn clone(&self) -> ToolTimeoutManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more