use clap::Parser;
use tracing_subscriber::EnvFilter;
use qrush::engine::{run_engine, parse_queues};
#[derive(Parser, Debug)]
#[command(name = "qrush-engine", version, about = "Separate worker process runtime for QRush")]
struct Args {
#[arg(long, env = "QRUSH_ENGINE_REDIS_URL", default_value = "redis://127.0.0.1:6379")]
redis: String,
#[arg(long, default_value = "default:10")]
queues: String,
#[arg(long, default_value_t = 5)]
shutdown_grace_secs: u64,
}
#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
match dotenvy::dotenv() {
Ok(path) => println!("Loaded .env from: {}", path.display()),
Err(_) => println!("⚠️ No .env file found, using environment variables"),
}
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
let args = Args::parse();
let redis_url = std::env::var("QRUSH_ENGINE_REDIS_URL")
.or_else(|_| std::env::var("REDIS_URL"))
.unwrap_or_else(|_| args.redis.clone());
let queues = parse_queues(&args.queues);
run_engine(redis_url, queues, args.shutdown_grace_secs).await
}