add tests and fix job impl

This commit is contained in:
Timur Gordon
2025-09-09 17:54:09 +02:00
parent 629d59f7db
commit d744c2cd16
21 changed files with 1067 additions and 393 deletions

View File

@@ -1,60 +0,0 @@
use actor_system::AsyncWorker;
use clap::Parser;
use log::info;
use std::sync::Arc;
use tokio::sync::mpsc;
#[derive(Parser, Debug)]
#[command(name = "actor_system")]
#[command(about = "System Actor - Asynchronous job processing actor")]
struct Args {
/// Database path
#[arg(short, long, default_value = "/tmp/system_db")]
db_path: String,
/// Redis URL
#[arg(short, long, default_value = "redis://localhost:6379")]
redis_url: String,
/// Preserve completed tasks in Redis
#[arg(short, long)]
preserve_tasks: bool,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
let args = Args::parse();
info!("Starting System Actor");
// Create shutdown channel
let (shutdown_tx, shutdown_rx) = mpsc::channel(1);
// Setup signal handler for graceful shutdown
let shutdown_tx_clone = shutdown_tx.clone();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.expect("Failed to listen for Ctrl+C");
info!("Received Ctrl+C, initiating shutdown...");
let _ = shutdown_tx_clone.send(()).await;
});
// Create and start the actor
let actor = Arc::new(
AsyncWorker::builder()
.db_path(args.db_path)
.redis_url(args.redis_url)
.build()?
);
let handle = baobab_actor::spawn_actor(actor, shutdown_rx);
info!("System Actor started, waiting for jobs...");
// Wait for the actor to complete
handle.await??;
info!("System Actor shutdown complete");
Ok(())
}

View File

@@ -1,71 +0,0 @@
use clap::Parser;
use log::info;
use std::time::Duration;
use tokio::sync::mpsc;
use actor_system::{spawn_async_actor};
#[derive(Parser, Debug)]
#[command(name = "async_actor")]
#[command(about = "Async Actor - processes jobs concurrently with SAL modules")]
struct Args {
/// Actor ID for this instance
#[arg(short, long)]
actor_id: String,
/// Database path
#[arg(short, long, default_value = "/tmp/actor_db")]
db_path: String,
/// Redis URL
#[arg(short, long, default_value = "redis://localhost:6379")]
redis_url: String,
/// Default timeout in seconds for job execution
#[arg(short, long, default_value = "300")]
timeout: u64,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
let args = Args::parse();
info!("Starting Async Actor with ID: {}", args.actor_id);
info!("Database path: {}", args.db_path);
info!("Redis URL: {}", args.redis_url);
info!("Default timeout: {}s", args.timeout);
// Create shutdown channel
let (_shutdown_tx, shutdown_rx) = mpsc::channel::<()>(1);
// Spawn the async actor
let handle = spawn_async_actor(
args.actor_id,
args.db_path,
args.redis_url,
shutdown_rx,
Duration::from_secs(args.timeout),
);
// Wait for the actor to complete
match handle.await {
Ok(result) => {
match result {
Ok(()) => {
info!("Async Actor completed successfully");
Ok(())
}
Err(e) => {
eprintln!("Async Actor error: {}", e);
Err(e)
}
}
}
Err(e) => {
eprintln!("Failed to join async actor task: {}", e);
Err(Box::new(e))
}
}
}

View File

@@ -1,70 +0,0 @@
use clap::Parser;
use log::info;
use tokio::sync::mpsc;
use actor_system::{spawn_sync_actor};
#[derive(Parser, Debug)]
#[command(name = "sync_actor")]
#[command(about = "Sync Actor - processes jobs sequentially with DSL modules")]
struct Args {
/// Actor ID for this instance
#[arg(short, long)]
actor_id: String,
/// Database path
#[arg(short, long, default_value = "/tmp/actor_db")]
db_path: String,
/// Redis URL
#[arg(short, long, default_value = "redis://localhost:6379")]
redis_url: String,
/// Preserve completed tasks in Redis (don't delete them)
#[arg(short, long, default_value = "false")]
preserve_tasks: bool,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
let args = Args::parse();
info!("Starting Sync Actor with ID: {}", args.actor_id);
info!("Database path: {}", args.db_path);
info!("Redis URL: {}", args.redis_url);
info!("Preserve tasks: {}", args.preserve_tasks);
// Create shutdown channel
let (_shutdown_tx, shutdown_rx) = mpsc::channel::<()>(1);
// Spawn the sync actor
let handle = spawn_sync_actor(
args.actor_id,
args.db_path,
args.redis_url,
shutdown_rx,
args.preserve_tasks,
);
// Wait for the actor to complete
match handle.await {
Ok(result) => {
match result {
Ok(()) => {
info!("Sync Actor completed successfully");
Ok(())
}
Err(e) => {
eprintln!("Sync Actor error: {}", e);
Err(e)
}
}
}
Err(e) => {
eprintln!("Failed to join sync actor task: {}", e);
Err(Box::new(e))
}
}
}

View File

@@ -46,7 +46,7 @@ fn create_app(args: &Args) -> Result<App> {
.unwrap_or_else(|_| ".".to_string());
let crate_root = PathBuf::from(crate_root);
let actor_path = crate_root.join("target/debug/actor_system");
let actor_path = crate_root.join("target/debug/runner_rust");
let example_dir = Some(crate_root.join("examples/scripts"));
let mut app = App::new(
@@ -68,7 +68,7 @@ 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_system");
let actor_path = PathBuf::from(crate_root).join("target/debug/runner_rust");
info!("🎬 Spawning actor process: {}", actor_path.display());
let mut cmd = Command::new(&actor_path);
@@ -123,7 +123,7 @@ async fn main() -> Result<()> {
info!("🚀 Starting Baobab Actor TUI...");
info!("Actor ID: sal (System Actor)");
info!("Actor Path: {}/target/debug/actor_system", crate_root);
info!("Actor Path: {}/target/debug/runner_rust", crate_root);
info!("Redis URL: {}", args.redis_url);
info!("Script Type: SAL");
info!("Example Directory: {}/examples/scripts", crate_root);