tcrm_task/
lib.rs

1//! # tcrm-task
2//!
3//! A Rust library for executing and managing system processes.
4//! Built for developers who need process execution with
5//! validation and real-time event monitoring.
6//!
7//! ## Features
8//!
9//! - **Real-time Events**: Monitor process output, state changes, and lifecycle events
10//! - **Timeout Management**: Configurable timeouts for process execution
11//! - **Stdin Support**: Send input to running processes
12//! - **Ready Indicators**: Detect when long-running processes are ready to accept requests
13//! - **Serialization**: Optional serde and flatbuffers support for persistence
14//!
15//! ## Quick Start
16//!
17//! ```rust
18//! use tcrm_task::tasks::{config::TaskConfig, async_tokio::spawner::TaskSpawner};
19//! use tokio::sync::mpsc;
20//!
21//! #[tokio::main]
22//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
23//!     // Create a simple command configuration
24//!     let config = TaskConfig::new("cmd")
25//!         .args(["/C", "echo", "Hello, World!"]);
26//!
27//!     // Validate the configuration
28//!     config.validate()?;
29//!
30//!     // Create a spawner and execute the task
31//!     let (tx, mut rx) = mpsc::channel(100);
32//!     let mut spawner = TaskSpawner::new("hello".to_string(), config);
33//!     
34//!     spawner.start_direct(tx).await?;
35//!
36//!     // Process events
37//!     while let Some(event) = rx.recv().await {
38//!         println!("Event: {:?}", event);
39//!     }
40//!
41//!     Ok(())
42//! }
43//! ```
44//!
45//! ## Advanced Usage
46//!
47//! ### Long-running Process with Ready Indicator
48//!
49//! ```rust
50//! use tcrm_task::tasks::{config::{TaskConfig, StreamSource}, async_tokio::spawner::TaskSpawner};
51//! use tokio::sync::mpsc;
52//!
53//! #[tokio::main]
54//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
55//!     let config = TaskConfig::new("cmd")
56//!         .args(["/C", "echo", "Server listening on"])
57//!         .ready_indicator("Server listening on")
58//!         .ready_indicator_source(StreamSource::Stdout)
59//!         .timeout_ms(30000);
60//!
61//!     let (tx, mut rx) = mpsc::channel(100);
62//!     let mut spawner = TaskSpawner::new("server".to_string(), config);
63//!     
64//!     spawner.start_direct(tx).await?;
65//!
66//!     // Wait for ready event
67//!     while let Some(event) = rx.recv().await {
68//!         if matches!(event, tcrm_task::tasks::event::TaskEvent::Ready { .. }) {
69//!             println!("Server is ready!");
70//!             break;
71//!         }
72//!     }
73//!
74//!     Ok(())
75//! }
76//! ```
77//!
78//! ### Process with Environment Variables and Working Directory
79//!
80//! ```rust
81//! use tcrm_task::tasks::{config::TaskConfig, async_tokio::spawner::TaskSpawner};
82//! use std::collections::HashMap;
83//!
84//! #[tokio::main]
85//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
86//!     let mut env = HashMap::new();
87//!     env.insert("RUST_LOG".to_string(), "debug".to_string());
88//!     env.insert("APP_ENV".to_string(), "production".to_string());
89//!
90//!     let config = TaskConfig::new("cmd")
91//!         .args(["/C", "dir"])
92//!         .working_dir("C:\\")
93//!         .env(env)
94//!         .timeout_ms(300000); // 5 minutes
95//!
96//!     config.validate()?;
97//!     
98//!     // ... execute task
99//!     Ok(())
100//! }
101//! ```
102//!
103//! ## Validation
104//!
105//! This library includes validation to prevent:
106//! - Path traversal  
107//! - Null byte
108//!
109//! All configurations are validated before execution using the built-in validator.
110//!
111//! ## Optional Features
112//!
113//! - `serde`: Enable serialization support for all types
114//! - `flatbuffers`: Enable `FlatBuffers` serialization for high-performance scenarios
115//! - `tracing`: Enable structured logging integration
116
117#[cfg(feature = "flatbuffers")]
118pub mod flatbuffers;
119pub mod helper;
120pub mod tasks;