archive unused / old code

This commit is contained in:
Timur Gordon
2025-08-05 12:59:02 +02:00
parent cd47d398de
commit 8ec7e70edf
25 changed files with 2 additions and 46 deletions

View File

@@ -0,0 +1,20 @@
[package]
name = "hero_examples"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "supervisor_worker_demo"
path = "supervisor_worker_demo.rs"
[dependencies]
hero_supervisor = { path = "../supervisor" }
hero_job = { path = "../job" }
tokio = { version = "1.0", features = ["full"] }
redis = { version = "0.25", features = ["tokio-comp"] }
serde_json = "1.0"
log = "0.4"
env_logger = "0.10"
colored = "2.0"
uuid = { version = "1.0", features = ["v4"] }
chrono = { version = "0.4", features = ["serde"] }

View File

@@ -0,0 +1,88 @@
//! Hero Supervisor Worker Demo
//!
//! This example demonstrates the new Hero Supervisor API with:
//! - Synchronous build() method
//! - Asynchronous start_workers() method
//! - Proper cleanup on program exit
//! - Signal handling for graceful shutdown
use colored::*;
use hero_supervisor::{SupervisorBuilder, ScriptType};
use std::time::Duration;
use tokio::signal;
async fn run_supervisor_demo() -> Result<(), Box<dyn std::error::Error>> {
println!("{}", "🚀 Hero Supervisor Demo - New API".cyan().bold());
println!("{}", "Building supervisor synchronously...".yellow());
// Build supervisor synchronously (no .await needed)
let supervisor = SupervisorBuilder::new()
.redis_url("redis://127.0.0.1:6379")
.osis_worker("/usr/local/bin/osis_worker")
.sal_worker("/usr/local/bin/sal_worker")
.v_worker("/usr/local/bin/v_worker")
.python_worker("/usr/local/bin/python_worker")
.worker_env_var("REDIS_URL", "redis://127.0.0.1:6379")
.worker_env_var("LOG_LEVEL", "info")
.build()?;
println!("{}", "✅ Supervisor built successfully!".green());
println!("{}", "Starting workers asynchronously...".yellow());
// Start workers asynchronously
supervisor.start_workers().await?;
println!("{}", "✅ All workers started successfully!".green());
// Demonstrate job creation and execution
println!("{}", "\n📋 Creating and running test jobs...".cyan().bold());
// Create and run a test job
println!("📝 Creating and running OSIS job...");
// Submit and run the job
match supervisor.new_job()
.script_type(ScriptType::OSIS)
.script("println('Hello from OSIS worker!')")
.timeout(Duration::from_secs(30))
.await_response().await {
Ok(result) => {
println!("{}", format!("✅ Job completed successfully: {}", result).green());
}
Err(e) => {
println!("{}", format!("❌ Job failed: {}", e).red());
}
}
// Wait for interrupt signal
println!("{}", "\n⏳ Press Ctrl+C to shutdown gracefully...".yellow());
signal::ctrl_c().await?;
println!("{}", "\n🛑 Shutdown signal received, cleaning up...".yellow().bold());
// Cleanup workers before exit
supervisor.cleanup_and_shutdown().await?;
println!("{}", "✅ Cleanup completed. Goodbye!".green().bold());
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging
env_logger::Builder::from_default_env()
.filter_level(log::LevelFilter::Info)
.init();
println!("{}", "Hero Supervisor Demo".cyan().bold());
println!("{}", "This demo shows the new synchronous build API".yellow());
println!();
// Run the demo
if let Err(e) = run_supervisor_demo().await {
eprintln!("{}", format!("Demo failed: {}", e).red().bold());
std::process::exit(1);
}
Ok(())
}