Update runner to use engine factory pattern with Rhai packages

- Reverted from generic Package approach to factory function pattern
- Factory creates Engine::new_raw() + registers package (efficient)
- AsyncRunner and SyncRunner use engine_factory: Arc<dyn Fn() -> Engine>
- Each job gets a fresh engine instance (cheap with factory pattern)
- Package is created once inside factory, engines reuse it
This commit is contained in:
Timur Gordon
2025-10-28 12:20:45 +01:00
parent 0c918a8f5f
commit 564b81b708
3 changed files with 8 additions and 9 deletions

View File

@@ -1,9 +1,8 @@
use crate::job::Job;
use log::{debug, error, info};
use rhai::{Dynamic, Engine};
use std::sync::Arc;
use crate::runner_trait::Runner;
use log::{debug, error, info};
use rhai::{Engine, Dynamic};
use std::sync::Arc;
/// Configuration for sync runner instances
#[derive(Debug, Clone)]
@@ -73,7 +72,7 @@ impl Runner for SyncRunner {
debug!("Sync Runner '{}', Job {}: Processing started.", runner_id, job_id);
info!("Sync Runner '{}' processing job_id: {}. Script: {:.50}...", job.context_id, job_id, job.payload);
// Create a new engine instance for this job execution
// Create a new engine instance (cheap with factory pattern)
let mut engine = (self.engine_factory)();
// Execute the script