Compare commits
2 Commits
5140531832
...
5fd068f45d
Author | SHA1 | Date | |
---|---|---|---|
|
5fd068f45d | ||
|
c19f938fde |
28
Cargo.lock
generated
28
Cargo.lock
generated
@@ -6,6 +6,7 @@ version = 4
|
|||||||
name = "actor_osis"
|
name = "actor_osis"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"baobab_actor",
|
"baobab_actor",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -191,11 +192,13 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "baobab_actor"
|
name = "baobab_actor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#6c5c97e64782f7d05ff22bbafba2498f4b906463"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"crossterm",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"hero_job",
|
"hero_job",
|
||||||
"hero_supervisor",
|
"hero_supervisor",
|
||||||
@@ -203,6 +206,7 @@ dependencies = [
|
|||||||
"heromodels-derive",
|
"heromodels-derive",
|
||||||
"heromodels_core",
|
"heromodels_core",
|
||||||
"log",
|
"log",
|
||||||
|
"ratatui",
|
||||||
"redis",
|
"redis",
|
||||||
"rhai",
|
"rhai",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -337,9 +341,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.42"
|
version = "4.5.43"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882"
|
checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -347,9 +351,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.42"
|
version = "4.5.43"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966"
|
checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@@ -935,9 +939,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.4.11"
|
version = "0.4.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785"
|
checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic-waker",
|
"atomic-waker",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -978,7 +982,7 @@ checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_job"
|
name = "hero_job"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#6c5c97e64782f7d05ff22bbafba2498f4b906463"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
@@ -993,7 +997,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_logger"
|
name = "hero_logger"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git?branch=logger#9c4fa1a78bf3cbeb57802d261ee9c9fb115ba219"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git?branch=logger#0da7b9363c2956e6f17ac78232152c549f1d5e68"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -1010,7 +1014,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_supervisor"
|
name = "hero_supervisor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#6c5c97e64782f7d05ff22bbafba2498f4b906463"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -1188,7 +1192,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2 0.4.11",
|
"h2 0.4.12",
|
||||||
"http 1.3.1",
|
"http 1.3.1",
|
||||||
"http-body 1.0.1",
|
"http-body 1.0.1",
|
||||||
"httparse",
|
"httparse",
|
||||||
@@ -2459,7 +2463,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "reth-ipc"
|
name = "reth-ipc"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
source = "git+https://github.com/paradigmxyz/reth#bf2700aa3e722a8f51b57cea9a71045da5420c1a"
|
source = "git+https://github.com/paradigmxyz/reth#59e4a5556fa54f1c210e45412b6a91f2351bea19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures",
|
"futures",
|
||||||
|
@@ -9,7 +9,11 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "actor_osis"
|
name = "actor_osis"
|
||||||
path = "cmd/actor_osis.rs"
|
path = "cmd/actor.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "actor_osis_tui"
|
||||||
|
path = "cmd/terminal_ui.rs"
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "engine"
|
name = "engine"
|
||||||
@@ -22,6 +26,7 @@ path = "examples/actor.rs"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
redis = { version = "0.25.0", features = ["tokio-comp"] }
|
redis = { version = "0.25.0", features = ["tokio-comp"] }
|
||||||
rhai = { version = "1.21.0", features = ["std", "sync", "decimal", "internals"] }
|
rhai = { version = "1.21.0", features = ["std", "sync", "decimal", "internals"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
11
README.md
11
README.md
@@ -38,4 +38,13 @@ let handle = spawn_osis_actor(
|
|||||||
- **Actor ID**: `"osis"` (constant)
|
- **Actor ID**: `"osis"` (constant)
|
||||||
- **Actor Type**: `"OSIS"`
|
- **Actor Type**: `"OSIS"`
|
||||||
- **Processing Model**: Sequential, blocking
|
- **Processing Model**: Sequential, blocking
|
||||||
- **Script Engine**: Rhai with OSIS-specific DSL extensions
|
- **Script Engine**: Rhai with OSIS-specific DSL extensions
|
||||||
|
|
||||||
|
## Binaries
|
||||||
|
|
||||||
|
- `actor.rs`: The actor binary, runs actor. `cargo run --bin actor_osis`
|
||||||
|
- `terminal_ui.rs`: The TUI binary, runs actor with TUI. `cargo run --bin actor_osis_tui`
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
The `examples` directory contains example scripts that can be used to test the actor. The examples are stored in the `examples/scripts` directory.
|
148
cmd/terminal_ui.rs
Normal file
148
cmd/terminal_ui.rs
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
//! Simplified main function for Baobab Actor TUI
|
||||||
|
//!
|
||||||
|
//! This binary provides a clean entry point for the actor monitoring and job dispatch interface.
|
||||||
|
|
||||||
|
use anyhow::{Result, Context};
|
||||||
|
use baobab_actor::terminal_ui::{App, setup_and_run_tui};
|
||||||
|
use clap::Parser;
|
||||||
|
use log::{info, warn, error};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::{Child, Command};
|
||||||
|
use tokio::signal;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(name = "baobab-actor-tui")]
|
||||||
|
#[command(about = "Terminal UI for Baobab Actor - Monitor and dispatch jobs to a single actor")]
|
||||||
|
struct Args {
|
||||||
|
/// Redis URL for job queue
|
||||||
|
#[arg(short, long, default_value = "redis://localhost:6379")]
|
||||||
|
redis_url: String,
|
||||||
|
|
||||||
|
/// Enable verbose logging
|
||||||
|
#[arg(short, long)]
|
||||||
|
verbose: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize logging based on verbosity level
|
||||||
|
fn init_logging(verbose: bool) {
|
||||||
|
if verbose {
|
||||||
|
env_logger::Builder::from_default_env()
|
||||||
|
.filter_level(log::LevelFilter::Debug)
|
||||||
|
.init();
|
||||||
|
} else {
|
||||||
|
env_logger::Builder::from_default_env()
|
||||||
|
.filter_level(log::LevelFilter::Info)
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create and configure the TUI application
|
||||||
|
fn create_app(args: &Args) -> Result<App> {
|
||||||
|
let actor_id = "osis".to_string();
|
||||||
|
|
||||||
|
// Get the crate root directory
|
||||||
|
let crate_root = std::env::var("CARGO_MANIFEST_DIR")
|
||||||
|
.unwrap_or_else(|_| ".".to_string());
|
||||||
|
let crate_root = PathBuf::from(crate_root);
|
||||||
|
|
||||||
|
let actor_path = crate_root.join("target/debug/actor_osis");
|
||||||
|
let example_dir = Some(crate_root.join("examples/scripts"));
|
||||||
|
|
||||||
|
App::new(
|
||||||
|
actor_id,
|
||||||
|
actor_path,
|
||||||
|
args.redis_url.clone(),
|
||||||
|
example_dir,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Spawn the actor binary as a background process
|
||||||
|
fn spawn_actor_process(_args: &Args) -> Result<Child> {
|
||||||
|
// Get the crate root directory
|
||||||
|
let crate_root = std::env::var("CARGO_MANIFEST_DIR")
|
||||||
|
.unwrap_or_else(|_| ".".to_string());
|
||||||
|
let actor_path = PathBuf::from(crate_root).join("target/debug/actor_osis");
|
||||||
|
info!("🎬 Spawning actor process: {}", actor_path.display());
|
||||||
|
|
||||||
|
let mut cmd = Command::new(&actor_path);
|
||||||
|
|
||||||
|
// Redirect stdout and stderr to null to prevent logs from interfering with TUI
|
||||||
|
cmd.stdout(std::process::Stdio::null())
|
||||||
|
.stderr(std::process::Stdio::null());
|
||||||
|
|
||||||
|
// Spawn the process
|
||||||
|
let child = cmd
|
||||||
|
.spawn()
|
||||||
|
.with_context(|| format!("Failed to spawn actor process: {}", actor_path.display()))?;
|
||||||
|
|
||||||
|
info!("✅ Actor process spawned with PID: {}", child.id());
|
||||||
|
Ok(child)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cleanup function to terminate actor process
|
||||||
|
fn cleanup_actor_process(mut actor_process: Child) {
|
||||||
|
info!("🧹 Cleaning up actor process...");
|
||||||
|
|
||||||
|
match actor_process.try_wait() {
|
||||||
|
Ok(Some(status)) => {
|
||||||
|
info!("Actor process already exited with status: {}", status);
|
||||||
|
}
|
||||||
|
Ok(None) => {
|
||||||
|
info!("Terminating actor process...");
|
||||||
|
if let Err(e) = actor_process.kill() {
|
||||||
|
error!("Failed to kill actor process: {}", e);
|
||||||
|
} else {
|
||||||
|
match actor_process.wait() {
|
||||||
|
Ok(status) => info!("Actor process terminated with status: {}", status),
|
||||||
|
Err(e) => error!("Failed to wait for actor process: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to check actor process status: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
// Initialize logging
|
||||||
|
init_logging(args.verbose);
|
||||||
|
|
||||||
|
let crate_root = std::env::var("CARGO_MANIFEST_DIR")
|
||||||
|
.unwrap_or_else(|_| ".".to_string());
|
||||||
|
|
||||||
|
info!("🚀 Starting Baobab Actor TUI...");
|
||||||
|
info!("Actor ID: osis");
|
||||||
|
info!("Actor Path: {}/target/debug/actor_osis", crate_root);
|
||||||
|
info!("Redis URL: {}", args.redis_url);
|
||||||
|
info!("Example Directory: {}/examples/scripts", crate_root);
|
||||||
|
|
||||||
|
// Spawn the actor process first
|
||||||
|
let actor_process = spawn_actor_process(&args)?;
|
||||||
|
|
||||||
|
// Give the actor a moment to start up
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||||
|
|
||||||
|
// Create app and run TUI
|
||||||
|
let app = create_app(&args)?;
|
||||||
|
|
||||||
|
// Set up signal handling for graceful shutdown
|
||||||
|
let result = tokio::select! {
|
||||||
|
tui_result = setup_and_run_tui(app) => {
|
||||||
|
info!("TUI exited");
|
||||||
|
tui_result
|
||||||
|
}
|
||||||
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received Ctrl+C, shutting down...");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clean up the actor process
|
||||||
|
cleanup_actor_process(actor_process);
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
Reference in New Issue
Block a user