Skip to main content

execution_engine/
lib.rs

1//! Cloudops Execution Engine
2//!
3//! Production-ready async execution engine for system commands.
4//!
5//! ## Features
6//!
7//! - Async/non-blocking execution
8//! - Real-time output streaming
9//! - Semaphore-based concurrency control
10//! - Automatic memory cleanup
11//! - Resource limits (timeout, output size, concurrency)
12//! - Event-driven updates
13//!
14//! ## Example
15//!
16//! ```rust,no_run
17//! use execution_engine::*;
18//! use std::sync::Arc;
19//!
20//! #[tokio::main]
21//! async fn main() {
22//!     let config = ExecutionConfig::default();
23//!     let engine = Arc::new(ExecutionEngine::new(config).unwrap());
24//!
25//!     let request = ExecutionRequest {
26//!         id: Uuid::new_v4(),
27//!         command: Command::Shell {
28//!             command: "echo 'Hello'".to_string(),
29//!             shell: "/bin/bash".to_string(),
30//!         },
31//!         timeout_ms: Some(5000),
32//!         env: HashMap::new(),
33//!         working_dir: None,
34//!         output_log_path: None,
35//!         metadata: ExecutionMetadata::default(),
36//!     };
37//!
38//!     let execution_id = engine.execute(request).await.unwrap();
39//!
40//!     let result = engine.wait_for_completion(execution_id).await.unwrap();
41//!
42//!     println!("Output: {}", result.stdout);
43//! }
44//! ```
45
46// Module declarations
47mod cleanup;
48mod commands;
49mod config;
50mod engine;
51mod errors;
52mod events;
53mod executor;
54mod types;
55
56// Public exports
57pub use config::*;
58pub use engine::ExecutionEngine;
59pub use errors::*;
60pub use events::*;
61pub use types::*;
62
63// Re-exports for convenience
64pub use chrono::{DateTime, Utc};
65pub use std::collections::HashMap;
66pub use std::path::PathBuf;
67pub use std::sync::Arc;
68pub use std::time::Duration;
69pub use tokio::sync::RwLock;
70pub use uuid::Uuid;
71
72// Type aliases for complex types
73/// Type alias for the execution map (shared state across threads)
74pub type ExecutionMap = Arc<RwLock<HashMap<Uuid, Arc<RwLock<types::ExecutionState>>>>>;
75
76/// Type alias for a single execution handle
77pub type ExecutionHandle = Arc<RwLock<types::ExecutionState>>;
78
79/// Type alias for the cancellation token map
80pub type CancellationTokenMap = Arc<RwLock<HashMap<Uuid, tokio_util::sync::CancellationToken>>>;