captain_workflow_manager/executor/
dry_run_executor.rs

1use crate::ExpandedDescr;
2
3use super::*;
4pub struct DryRunExecutorBuilder {}
5
6impl ExecutorBuilder for DryRunExecutorBuilder {
7    type Executor = DryRunExecutor;
8
9    fn init<J: JobUnit>(
10        self,
11    ) -> (
12        Self::Executor,
13        Sender<ToRun<J>>,
14        Sender<ExecutorResult>,
15        Receiver<ExecutorResult>,
16    ) {
17        let to_run_chan = crossbeam_channel::unbounded::<ToRun<J>>();
18        let done_chan = crossbeam_channel::unbounded();
19        let thread_handle = {
20            let rcvr = to_run_chan.1.clone();
21            let sndr = done_chan.0.clone();
22            thread::Builder::new()
23                .spawn(move || {
24                    for to_run in rcvr.into_iter() {
25                        let j_idx = to_run.job_idx;
26
27                        let stdout = io::stdout();
28                        {
29                            let mut lock = stdout.lock();
30                            write!(lock, "Would submit job: {:#?} interpreted as: {:#?} ", to_run.job_unit, ExpandedDescr(to_run.job_unit())).unwrap();
31                            writeln!(lock, "\n").unwrap();
32                        }
33
34                        sndr.send(ExecutorResult::new_ok(j_idx)).unwrap()
35                    }
36                })
37                .unwrap()
38        };
39        (
40            DryRunExecutor {
41                thread: thread_handle,
42            },
43            to_run_chan.0,
44            done_chan.0,
45            done_chan.1,
46        )
47    }
48}
49
50pub struct DryRunExecutor {
51    thread: JoinHandle<()>,
52}
53
54impl Executor for DryRunExecutor {
55    fn join(self) -> Vec<std::thread::Result<()>> {
56        vec![self.thread.join()]
57    }
58}