actor trait improvements and ui implementation
This commit is contained in:
@@ -113,6 +113,32 @@ async fn execute_script_and_update_status(
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a job with the given engine, setting proper job context
|
||||
///
|
||||
/// This function sets up the engine with job context (DB_PATH, CALLER_ID, CONTEXT_ID)
|
||||
/// and evaluates the script. It returns the result or error without updating Redis.
|
||||
/// This allows actors to handle Redis updates according to their own patterns.
|
||||
pub async fn execute_job_with_engine(
|
||||
engine: &Engine,
|
||||
job: &Job,
|
||||
db_path: &str,
|
||||
) -> Result<Dynamic, Box<rhai::EvalAltResult>> {
|
||||
// Clone the engine to avoid mutating the original
|
||||
let mut engine_clone = engine.clone();
|
||||
|
||||
// Set up job context in the engine
|
||||
let mut db_config = rhai::Map::new();
|
||||
db_config.insert("DB_PATH".into(), db_path.to_string().into());
|
||||
db_config.insert("CALLER_ID".into(), job.caller_id.clone().into());
|
||||
db_config.insert("CONTEXT_ID".into(), job.context_id.clone().into());
|
||||
engine_clone.set_default_tag(Dynamic::from(db_config));
|
||||
|
||||
debug!("Actor for Context ID '{}': Evaluating script with Rhai engine (job context set).", job.context_id);
|
||||
|
||||
// Execute the script with the configured engine
|
||||
engine_clone.eval::<Dynamic>(&job.script)
|
||||
}
|
||||
|
||||
/// Clean up job from Redis if preserve_tasks is false
|
||||
async fn cleanup_job(
|
||||
redis_conn: &mut redis::aio::MultiplexedConnection,
|
||||
@@ -236,3 +262,6 @@ pub fn spawn_rhai_actor(
|
||||
// Re-export the main trait-based interface for convenience
|
||||
pub use actor_trait::{Actor, ActorConfig, spawn_actor};
|
||||
|
||||
// Re-export the shared job execution function
|
||||
pub use execute_job_with_engine;
|
||||
|
||||
|
Reference in New Issue
Block a user