use std::{
io,
io::Write,
process::Command,
thread::{self, JoinHandle},
};
use crossbeam_channel::{Receiver, Sender};
use petgraph::prelude::NodeIndex;
pub mod dry_run_executor;
pub use dry_run_executor::DryRunExecutorBuilder;
pub mod slurm_executor;
pub use slurm_executor::SlurmExecutorBuilder;
pub mod thread_local;
pub use thread_local::ThreadLocalExecutorBuilder;
use crate::{JobUnit, ToRun};
type JobResult = Result<(), String>;
#[derive(Debug)]
pub struct ExecutorResult {
pub(crate) job_idx: NodeIndex,
pub(crate) result: JobResult,
}
impl ExecutorResult {
pub fn new_ok(job_idx: NodeIndex) -> Self {
Self {
job_idx,
result: Ok(()),
}
}
pub fn new_error(job_idx: NodeIndex, err: String) -> Self {
Self {
job_idx,
result: Err(err)
}
}
}
pub trait ExecutorBuilder {
type Executor: Executor;
fn init<J: JobUnit>(
self,
) -> (
Self::Executor,
Sender<ToRun<J>>,
Sender<ExecutorResult>,
Receiver<ExecutorResult>,
);
}
pub trait Executor {
fn join(self) -> Vec<std::thread::Result<()>>;
}
fn create_out_dir<J: JobUnit>(j_u: &J) {
std::fs::create_dir_all(j_u.out_file().parent().unwrap()).unwrap();
if let Some(p) = j_u.log_file() {
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
}
}