27 lines
912 B
Rust
27 lines
912 B
Rust
use std::error::Error;
|
|
use regex::Regex;
|
|
use crate::job_run::JobRun;
|
|
use crate::{PartitionRef, WantDetail};
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct JobConfiguration {
|
|
pub label: String,
|
|
pub pattern: String,
|
|
pub entrypoint: String,
|
|
}
|
|
|
|
impl JobConfiguration {
|
|
/** Launch job to build the partitions specified by the provided wants. */
|
|
pub fn spawn(&self, wants: Vec<WantDetail>) -> Result<JobRun, Box<dyn Error>> {
|
|
let wanted_refs: Vec<PartitionRef> = wants.iter().flat_map(|want| want.refs.clone()).collect();
|
|
let args: Vec<String> = wanted_refs.iter().map(|pref| pref.r#ref.clone()).collect();
|
|
JobRun::spawn(self.entrypoint.clone(), args)
|
|
}
|
|
|
|
pub fn matches(&self, refs: &PartitionRef) -> bool {
|
|
let regex = Regex::new(&self.pattern)
|
|
.expect(&format!("Invalid regex pattern: {}", self.pattern));
|
|
regex.is_match(&refs.r#ref)
|
|
}
|
|
}
|