61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
use actor_osis::OSISActor;
|
|
use clap::Parser;
|
|
use log::info;
|
|
use std::sync::Arc;
|
|
use tokio::sync::mpsc;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(name = "actor_osis")]
|
|
#[command(about = "OSIS Actor - Synchronous job processing actor")]
|
|
struct Args {
|
|
/// Database path
|
|
#[arg(short, long, default_value = "/tmp/osis_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 OSIS 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(
|
|
OSISActor::builder()
|
|
.db_path(args.db_path)
|
|
.redis_url(args.redis_url)
|
|
.build()?
|
|
);
|
|
|
|
let handle = baobab_actor::spawn_actor(actor, shutdown_rx);
|
|
|
|
info!("OSIS Actor started, waiting for jobs...");
|
|
|
|
// Wait for the actor to complete
|
|
handle.await??;
|
|
|
|
info!("OSIS Actor shutdown complete");
|
|
Ok(())
|
|
}
|