actor execute job fix

This commit is contained in:
Timur Gordon 2025-08-06 12:56:25 +02:00
parent dcf0f41bb8
commit 6c5c97e647

View File

@ -119,24 +119,21 @@ async fn execute_script_and_update_status(
/// 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,
engine: &mut 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));
engine.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)
engine.eval::<Dynamic>(&job.script)
}
/// Clean up job from Redis if preserve_tasks is false
@ -262,6 +259,3 @@ 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;