diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-04 10:23:27 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:21:54 +0100 |
commit | 4f0eb2b11ac44ce4f3b2273dcd863c5e173689c1 (patch) | |
tree | b4ef4f7b0a66e66f9c52ef89c6e9d9cfe50d7bd4 /src/job | |
parent | 89e48c21245e1b09678363fcf157094c1234b277 (diff) |
Remove passing of additional env variables
This patch removes the passing around of additional environment
variables that were specified on the commandline and adds them directly
to the Job object instance upon creation.
This does not result in a netto-loss of code, but in a netto-loss of
complexity.
For this to be possible, we had to derive Clone for `JobResource`, which
we have to clone when creating the `Job` objects during the creation of
the jobsets from the `Tree` object.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/job')
-rw-r--r-- | src/job/job.rs | 4 | ||||
-rw-r--r-- | src/job/resource.rs | 8 | ||||
-rw-r--r-- | src/job/set.rs | 21 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/job/job.rs b/src/job/job.rs index 1046b5d..865fa69 100644 --- a/src/job/job.rs +++ b/src/job/job.rs @@ -32,7 +32,7 @@ pub struct Job { impl Job { - pub fn new(pkg: Package, image: ImageName, phases: Vec<PhaseName>) -> Self { + pub fn new(pkg: Package, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Self { let uuid = Uuid::new_v4(); Job { @@ -41,7 +41,7 @@ impl Job { image, script_shebang: String::from("#!/bin/bash"), // TODO Dont hardcode script_phases: phases, - resources: Vec::new(), + resources, } } diff --git a/src/job/resource.rs b/src/job/resource.rs index 6dba1ba..7e255f6 100644 --- a/src/job/resource.rs +++ b/src/job/resource.rs @@ -1,12 +1,18 @@ use crate::filestore::Artifact; /// TODO implement -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum JobResource { Environment(String, String), Artifact(Artifact) } +impl From<(String, String)> for JobResource { + fn from(tpl: (String, String)) -> Self { + JobResource::Environment(tpl.0, tpl.1) + } +} + impl JobResource { pub fn env(&self) -> Option<(&String, &String)> { match self { diff --git a/src/job/set.rs b/src/job/set.rs index a428cce..233110a 100644 --- a/src/job/set.rs +++ b/src/job/set.rs @@ -4,6 +4,7 @@ use tokio::stream::StreamExt; use crate::config::Configuration; use crate::filestore::MergedStores; use crate::job::Job; +use crate::job::JobResource; use crate::job::RunnableJob; use crate::package::Tree; use crate::phase::PhaseName; @@ -17,8 +18,8 @@ pub struct JobSet { } impl JobSet { - pub fn sets_from_tree(t: Tree, image: ImageName, phases: Vec<PhaseName>) -> Result<Vec<JobSet>> { - tree_into_jobsets(t, image, phases) + pub fn sets_from_tree(t: Tree, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> { + tree_into_jobsets(t, image, phases, resources) } fn is_empty(&self) -> bool { @@ -37,8 +38,8 @@ impl JobSet { } /// Get the tree as sets of jobs, the deepest level of the tree first -fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>) -> Result<Vec<JobSet>> { - fn inner(tree: Tree, image: &ImageName, phases: &Vec<PhaseName>) -> Result<Vec<JobSet>> { +fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> { + fn inner(tree: Tree, image: &ImageName, phases: &Vec<PhaseName>, resources: &Vec<JobResource>) -> Result<Vec<JobSet>> { trace!("Creating jobsets for tree: {:?}", tree); let mut sets = vec![]; @@ -46,7 +47,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>) -> Re for (package, dep) in tree.into_iter() { trace!("Recursing for package: {:?}", package); - let mut sub_sets = inner(dep, image, phases)?; // recursion! + let mut sub_sets = inner(dep, image, phases, resources)?; // recursion! sets.append(&mut sub_sets); current_set.push(package); } @@ -56,7 +57,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>) -> Re set: current_set .into_iter() .map(|package| { - Job::new(package, image.clone(), phases.clone()) + Job::new(package, image.clone(), phases.clone(), resources.clone()) }) .collect(), }; @@ -74,7 +75,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>) -> Re Ok(result) } - inner(tree, &image, &phases).map(|mut v| { + inner(tree, &image, &phases, &resources).map(|mut v| { // reverse, because the highest level in the tree is added as first element in the vector // and the deepest level is last. // @@ -128,7 +129,7 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; - let js = JobSet::sets_from_tree(tree, image, phases); + let js = JobSet::sets_from_tree(tree, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); @@ -175,7 +176,7 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; - let js = JobSet::sets_from_tree(tree, image, phases); + let js = JobSet::sets_from_tree(tree, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); @@ -227,7 +228,7 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; - let js = JobSet::sets_from_tree(tree, image, phases); + let js = JobSet::sets_from_tree(tree, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); |