pub mod local;
pub mod remote;
pub mod types;
use anyhow::Result;
use types::{ExecutionConfig, ExecutionMode, ExecutionResult};
pub type OutputCallback = Box<dyn Fn(&nbformat::v4::Output) + Send + Sync>;
#[async_trait::async_trait]
pub trait ExecutionBackend: Send {
async fn start(&mut self) -> Result<()>;
async fn execute_code(
&mut self,
code: &str,
cell_id: Option<&str>,
cell_index: Option<usize>,
on_output: Option<&OutputCallback>,
) -> Result<ExecutionResult>;
async fn stop(&mut self) -> Result<()>;
}
pub fn create_backend(config: ExecutionConfig) -> Result<Box<dyn ExecutionBackend>> {
match config.mode.clone() {
ExecutionMode::Local => Ok(Box::new(local::LocalExecutor::new(config)?)),
ExecutionMode::Remote { server_url, token } => Ok(Box::new(remote::RemoteExecutor::new(
config, server_url, token,
)?)),
}
}