Production deployment with zinit config

This commit is contained in:
Timur Gordon
2025-10-20 22:22:34 +02:00
parent 0c4d36248a
commit 58537982c4
10 changed files with 746 additions and 1 deletions

View File

@@ -3,9 +3,15 @@
/// This module provides two different engine configurations:
/// - `system`: SAL modules for system operations (async worker)
/// - `osis`: DSL modules for business operations (sync worker)
/// - `osiris`: DSL modules for business operations (sync worker)
pub mod system;
pub mod osis;
pub mod osiris;
pub use osis::create_osis_engine;
pub use system::create_system_engine;
pub use osiris::{create_osiris_engine, run_osiris_script};
// Re-export common Rhai types for convenience
pub use rhai::{Array, Dynamic, Engine, EvalAltResult, Map};

96
src/engine/osiris.rs Normal file
View File

@@ -0,0 +1,96 @@
/// OSIRIS Rhai Engine Integration
///
/// This module provides a Rhai engine configured with OSIRIS object support.
/// It allows Rhai scripts to create Notes, Events, and other OSIRIS objects
/// using a fluent builder pattern and store/retrieve them from HeroDB.
///
/// # Example Rhai Script
///
/// ```rhai
/// // Create a note with builder pattern
/// let note = note("notes")
/// .title("My First Note")
/// .content("This is the content of my note")
/// .tag("topic", "rust")
/// .tag("project", "osiris")
/// .mime("text/plain");
///
/// // Store the note
/// let id = put_note(note);
/// print(`Note stored with ID: ${id}`);
///
/// // Retrieve the note
/// let retrieved = get_note("notes", id);
/// print(`Retrieved: ${retrieved.get_title()}`);
///
/// // Query by tag
/// let ids = query("notes", "tags:tag", "project=osiris");
/// print(`Found ${ids.len()} notes`);
/// ```
use osiris::rhai_support::{register_note_api, register_event_api, OsirisInstance};
use rhai::Engine;
/// Create a new Rhai engine with OSIRIS support
///
/// # Arguments
/// * `herodb_url` - HeroDB connection URL (e.g., "redis://localhost:6379")
/// * `db_id` - Database ID to use
///
/// # Returns
/// A configured Rhai engine with OSIRIS objects and methods registered
pub fn create_osiris_engine(
herodb_url: &str,
db_id: u16,
) -> Result<Engine, Box<dyn std::error::Error>> {
let mut engine = Engine::new();
// Register Note and Event APIs
register_note_api(&mut engine);
register_event_api(&mut engine);
// Register OsirisInstance type
engine.build_type::<OsirisInstance>();
// Register a function to create OSIRIS instances
engine.register_fn("osiris", move |name: &str, url: &str, db_id: rhai::INT| -> Result<OsirisInstance, Box<rhai::EvalAltResult>> {
OsirisInstance::new(name, url, db_id as u16)
.map_err(|e| format!("Failed to create OSIRIS instance: {}", e).into())
});
Ok(engine)
}
/// Example: Run a Rhai script with OSIRIS support
pub fn run_osiris_script(
script: &str,
herodb_url: &str,
db_id: u16,
) -> Result<(), Box<dyn std::error::Error>> {
let engine = create_osiris_engine(herodb_url, db_id)?;
engine.run(script)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_create_engine() {
let engine = create_osiris_engine("redis://localhost:6379", 1);
assert!(engine.is_ok());
}
#[test]
#[ignore] // Requires HeroDB running
fn test_run_script() {
let script = r#"
let note = note("notes");
print(note);
"#;
let result = run_osiris_script(script, "redis://localhost:6379", 1);
assert!(result.is_ok());
}
}

View File

@@ -15,7 +15,8 @@ pub use engine::system::{register_sal_modules, create_system_engine};
pub use engine::osis::{register_dsl_modules, create_osis_engine, create_shared_osis_engine};
// Re-export job types from local job module
pub use job::{Job, JobStatus, JobError, JobBuilder, Client};
pub use job::{Job, JobStatus, JobError, JobBuilder};
pub use client::{Client, ClientBuilder};
pub use redis::AsyncCommands;
use log::{error, info};