pub mod local;
pub mod remote;
use somatize_compiler::ExecutionPlan;
use somatize_core::cache::CacheStore;
use somatize_core::error::Result;
use somatize_core::value::Value;
use std::collections::HashMap;
use crate::EventBus;
use crate::executor::GraphInfo;
use crate::node_catalog::NodeCatalog;
use std::sync::Arc;
pub struct RunContext<'a> {
pub catalog: &'a NodeCatalog,
pub cache: &'a dyn CacheStore,
pub events: &'a Arc<EventBus>,
pub run_id: &'a str,
pub graph_info: GraphInfo,
pub seed: Option<i64>,
pub driver: Option<crate::effects::EffectDriver>,
}
impl<'a> RunContext<'a> {
pub fn new(
catalog: &'a NodeCatalog,
cache: &'a dyn CacheStore,
events: &'a Arc<EventBus>,
run_id: &'a str,
graph_info: GraphInfo,
) -> Self {
Self {
catalog,
cache,
events,
run_id,
graph_info,
seed: None,
driver: None,
}
}
pub fn with_seed(mut self, seed: Option<i64>) -> Self {
self.seed = seed;
self
}
pub fn with_driver(mut self, driver: crate::effects::EffectDriver) -> Self {
self.driver = Some(driver);
self
}
pub fn linear(
catalog: &'a NodeCatalog,
cache: &'a dyn CacheStore,
events: &'a Arc<EventBus>,
run_id: &'a str,
plan: &ExecutionPlan,
) -> Self {
let ids = plan.node_ids();
Self::new(catalog, cache, events, run_id, GraphInfo::for_linear(&ids))
}
pub(crate) fn driver(&self) -> Option<crate::effects::EffectDriver> {
self.driver.clone()
}
}
pub trait Runner: Send + Sync {
fn fit(
&self,
plan: &ExecutionPlan,
ctx: &RunContext<'_>,
input: &Value,
y: Option<&Value>,
) -> Result<(Value, HashMap<String, Value>)>;
fn forward(&self, plan: &ExecutionPlan, ctx: &RunContext<'_>, input: &Value) -> Result<Value>;
}
pub use local::LocalRunner;
pub use remote::{RemoteRunner, Transport};