folk_runtime_pipe/
runtime.rs1use std::sync::Arc;
4
5use anyhow::Result;
6use async_trait::async_trait;
7use folk_core::runtime::{Runtime, WorkerHandle};
8use tracing::info;
9
10use crate::handle::PipeWorkerHandle;
11use crate::spawn::spawn_worker;
12
13#[derive(Clone)]
14pub struct PipeConfig {
15 pub php: String,
16 pub script: String,
17}
18
19pub struct PipeRuntime {
20 config: Arc<PipeConfig>,
21}
22
23impl PipeRuntime {
24 pub fn new(config: PipeConfig) -> Self {
25 Self {
26 config: Arc::new(config),
27 }
28 }
29}
30
31#[async_trait]
32impl Runtime for PipeRuntime {
33 async fn spawn(&self) -> Result<Box<dyn WorkerHandle>> {
34 info!(php = %self.config.php, script = %self.config.script, "spawning worker");
35 let spawned = spawn_worker(&self.config.php, &self.config.script)?;
36 Ok(Box::new(PipeWorkerHandle::new(
37 spawned.child,
38 spawned.task_master,
39 spawned.control_master,
40 )))
41 }
42}