fluentci_ext/
service.rs

1use std::{fs, process::ExitStatus, sync::mpsc::Sender};
2
3use crate::{exec, pkgx::Pkgx, Extension};
4use anyhow::Error;
5use fluentci_types::Output;
6
7#[derive(Default)]
8pub struct Service {}
9
10impl Extension for Service {
11    fn exec(
12        &mut self,
13        yaml: &str,
14        tx: Sender<String>,
15        out: Output,
16        last_cmd: bool,
17        work_dir: &str,
18    ) -> Result<ExitStatus, Error> {
19        self.setup()?;
20
21        if yaml.is_empty() {
22            return Ok(ExitStatus::default());
23        }
24
25        fs::create_dir_all(".fluentci")?;
26
27        fs::write(".fluentci/process-compose.yaml", yaml)?;
28
29        exec(
30            "pkgx process-compose up -t=false -f .fluentci/process-compose.yaml -u .fluentci/process-compose.sock",
31            tx,
32            out,
33            last_cmd,
34            work_dir,
35        )
36    }
37
38    fn setup(&self) -> Result<(), Error> {
39        Pkgx::default().setup()?;
40        Ok(())
41    }
42
43    fn post_setup(&self, tx: Sender<String>) -> Result<ExitStatus, Error> {
44        exec(
45            "pkgx process-compose down -u process-compose.sock",
46            tx,
47            Output::Stdout,
48            true,
49            ".fluentci",
50        )
51    }
52}