escher-execution-engine 0.1.2

Production-ready async execution engine for system commands
Documentation
// Simple Python Execution Example
//
// This shows the simplest way to execute your own Python script.
// Run with: cargo run --example simple_python

use execution_engine::*;
use std::sync::Arc;
use std::collections::HashMap;

#[tokio::main]
async fn main() {
    // Step 1: Create the execution engine
    let config = ExecutionConfig::default();
    let engine = Arc::new(ExecutionEngine::new(config).unwrap());

    // Step 2: Specify your Python script path
    // CHANGE THIS to your actual Python file path
    let python_script_path = "test-scripts/demo.py";

    // Step 3: Create an execution request
    let request = ExecutionRequest {
        id: Uuid::new_v4(),
        command: Command::Script {
            path: PathBuf::from(python_script_path),
            interpreter: Some("python3".to_string()), // or "python" depending on your system
        },
        env: std::env::vars().collect(), // Inherit current environment variables
        working_dir: Some(std::env::current_dir().unwrap()), // Set current working directory
        timeout_ms: Some(30000),      // 30 second timeout
        output_log_path: None,
        metadata: ExecutionMetadata::default(),
    };

    // Step 4: Execute the script
    println!("Executing Python script: {}", python_script_path);

    match engine.execute(request).await {
        Ok(execution_id) => {
            println!("✓ Script started with ID: {}", execution_id);

            // Step 5: Wait for completion and get result
            match engine.wait_for_completion(execution_id).await {
                Ok(result) => {
                    println!("\n=== Execution Result ===");
                    println!("Status: {:?}", result.status);
                    println!("Success: {}", result.success);
                    println!("Exit Code: {}", result.exit_code);
                    println!("Duration: {:?}", result.duration);

                    if !result.stdout.is_empty() {
                        println!("\n--- Output (stdout) ---");
                        println!("{}", result.stdout);
                    }

                    if !result.stderr.is_empty() {
                        println!("\n--- Errors (stderr) ---");
                        println!("{}", result.stderr);
                    }

                    if let Some(error) = result.error {
                        println!("\n--- Error Message ---");
                        println!("{}", error);
                    }
                }
                Err(e) => {
                    println!("✗ Error waiting for completion: {}", e);
                }
            }
        }
        Err(e) => {
            println!("✗ Failed to start execution: {}", e);
        }
    }
}