Files
runner_rust/cmd/async_actor.rs
2025-09-09 15:42:20 +02:00

72 lines
1.8 KiB
Rust

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))
}
}
}