Restructure Osiris: separate core, client, and server crates to avoid circular dependencies
This commit is contained in:
94
core/src/bin/runner.rs
Normal file
94
core/src/bin/runner.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
/// OSIRIS Runner
|
||||
///
|
||||
/// A standalone runner for executing OSIRIS Rhai scripts.
|
||||
/// Can run in script mode (single execution) or daemon mode (continuous).
|
||||
///
|
||||
/// Usage:
|
||||
/// ```bash
|
||||
/// # Script mode
|
||||
/// cargo run --bin runner -- runner1 --script "let note = note('test').title('Hi'); put_note(note);"
|
||||
///
|
||||
/// # Daemon mode (requires runner_rust infrastructure)
|
||||
/// cargo run --bin runner -- runner1 --redis-url redis://localhost:6379
|
||||
/// ```
|
||||
|
||||
use clap::Parser;
|
||||
use osiris::{create_osiris_engine, OsirisContext};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about = "OSIRIS Rhai Script Runner", long_about = None)]
|
||||
struct Args {
|
||||
/// Runner ID
|
||||
runner_id: String,
|
||||
|
||||
/// HeroDB URL
|
||||
#[arg(short = 'r', long, default_value = "redis://localhost:6379")]
|
||||
redis_url: String,
|
||||
|
||||
/// HeroDB database ID
|
||||
#[arg(short = 'd', long, default_value_t = 1)]
|
||||
db_id: u16,
|
||||
|
||||
/// Script to execute in single-job mode (optional)
|
||||
#[arg(short, long)]
|
||||
script: Option<String>,
|
||||
|
||||
/// Script file to execute
|
||||
#[arg(short = 'f', long)]
|
||||
script_file: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Initialize logging
|
||||
env_logger::init();
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
println!("🚀 OSIRIS Runner");
|
||||
println!("Runner ID: {}", args.runner_id);
|
||||
println!("HeroDB: {} (DB {})", args.redis_url, args.db_id);
|
||||
println!();
|
||||
|
||||
// Determine script source
|
||||
let script_content = if let Some(script) = args.script {
|
||||
script
|
||||
} else if let Some(file_path) = args.script_file {
|
||||
std::fs::read_to_string(&file_path)
|
||||
.map_err(|e| format!("Failed to read script file '{}': {}", file_path, e))?
|
||||
} else {
|
||||
return Err("No script provided. Use --script or --script-file".into());
|
||||
};
|
||||
|
||||
println!("📝 Executing script...\n");
|
||||
println!("─────────────────────────────────────");
|
||||
|
||||
// Create engine
|
||||
let mut engine = create_osiris_engine()?;
|
||||
|
||||
// Set up context tags with SIGNATORIES
|
||||
let mut tag_map = rhai::Map::new();
|
||||
let signatories: rhai::Array = vec![rhai::Dynamic::from(args.runner_id.clone())];
|
||||
tag_map.insert("SIGNATORIES".into(), rhai::Dynamic::from(signatories));
|
||||
tag_map.insert("HERODB_URL".into(), rhai::Dynamic::from(args.redis_url.clone()));
|
||||
tag_map.insert("DB_ID".into(), rhai::Dynamic::from(args.db_id as i64));
|
||||
engine.set_default_tag(rhai::Dynamic::from(tag_map));
|
||||
|
||||
let mut scope = rhai::Scope::new();
|
||||
|
||||
match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &script_content) {
|
||||
Ok(result) => {
|
||||
println!("─────────────────────────────────────");
|
||||
println!("\n✅ Script completed successfully!");
|
||||
if !result.is_unit() {
|
||||
println!("Result: {}", result);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
println!("─────────────────────────────────────");
|
||||
println!("\n❌ Script execution failed!");
|
||||
println!("Error: {}", e);
|
||||
Err(Box::new(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user