pub struct ParallelDBExecutor { /* private fields */ }Expand description
Parallel Database Executor
Executes multiple database queries concurrently across different databases, collecting results and providing detailed execution statistics.
§Example
use rust_logic_graph::multi_db::ParallelDBExecutor;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut executor = ParallelDBExecutor::new();
// Register query closures for different databases
executor
.add_query("oms_db", "user_query", Box::new(|| Box::pin(async {
// Execute query against OMS database
Ok(serde_json::json!({"user_id": 123, "name": "John"}))
})))
.add_query("inventory_db", "stock_query", Box::new(|| Box::pin(async {
// Execute query against Inventory database
Ok(serde_json::json!({"product_id": "PROD-001", "qty": 50}))
})));
let results = executor.execute_all().await?;
println!("Executed {} queries in parallel", results.len());
Ok(())
}Implementations§
Source§impl ParallelDBExecutor
impl ParallelDBExecutor
Sourcepub fn with_max_concurrent(self, max: usize) -> Self
pub fn with_max_concurrent(self, max: usize) -> Self
Set maximum number of concurrent queries
Sourcepub fn add_query<F, Fut>(
&mut self,
database: impl Into<String>,
query_id: impl Into<String>,
query_fn: F,
) -> &mut Self
pub fn add_query<F, Fut>( &mut self, database: impl Into<String>, query_id: impl Into<String>, query_fn: F, ) -> &mut Self
Add a query to execute
§Arguments
database- Database identifier (e.g., “oms_db”, “inventory_db”)query_id- Unique query identifier for trackingquery_fn- Async closure that executes the query
Sourcepub async fn execute_all(
&mut self,
) -> Result<HashMap<String, QueryResult>, RustLogicGraphError>
pub async fn execute_all( &mut self, ) -> Result<HashMap<String, QueryResult>, RustLogicGraphError>
Execute all registered queries in parallel
Returns a HashMap with query_id as key and QueryResult as value.
§Errors
If any query fails, returns the first encountered error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ParallelDBExecutor
impl !RefUnwindSafe for ParallelDBExecutor
impl Send for ParallelDBExecutor
impl !Sync for ParallelDBExecutor
impl Unpin for ParallelDBExecutor
impl !UnwindSafe for ParallelDBExecutor
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
Mutably borrows from an owned value. Read more
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>
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 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>
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