80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use actor_system::spawn_sync_runner;
|
|
use clap::Parser;
|
|
use log::{error, info};
|
|
use tokio::sync::mpsc;
|
|
|
|
mod engine;
|
|
use engine::create_osis_engine;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct Args {
|
|
/// Runner ID
|
|
runner_id: String,
|
|
|
|
/// Database path
|
|
#[arg(short, long, default_value = "/tmp/osis.db")]
|
|
db_path: String,
|
|
|
|
/// Redis URL
|
|
#[arg(short = 'r', long, default_value = "redis://localhost:6379")]
|
|
redis_url: String,
|
|
|
|
/// Preserve tasks after completion
|
|
#[arg(short, long, default_value_t = false)]
|
|
preserve_tasks: bool,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
// Initialize logging
|
|
env_logger::init();
|
|
|
|
let args = Args::parse();
|
|
|
|
info!("Starting OSIS Sync Runner with ID: {}", args.runner_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);
|
|
|
|
// Setup signal handling 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;
|
|
});
|
|
|
|
// Spawn the sync runner with engine factory
|
|
let runner_handle = spawn_sync_runner(
|
|
args.runner_id.clone(),
|
|
args.db_path,
|
|
args.redis_url,
|
|
shutdown_rx,
|
|
args.preserve_tasks,
|
|
create_osis_engine,
|
|
);
|
|
|
|
info!("OSIS Sync Runner '{}' started successfully", args.runner_id);
|
|
|
|
// Wait for the runner to complete
|
|
match runner_handle.await {
|
|
Ok(Ok(())) => {
|
|
info!("OSIS Sync Runner '{}' shut down successfully", args.runner_id);
|
|
}
|
|
Ok(Err(e)) => {
|
|
error!("OSIS Sync Runner '{}' encountered an error: {}", args.runner_id, e);
|
|
return Err(e);
|
|
}
|
|
Err(e) => {
|
|
error!("Failed to join OSIS Sync Runner '{}' task: {}", args.runner_id, e);
|
|
return Err(Box::new(e));
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|