diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-04 15:36:30 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-04 17:05:34 +0100 |
commit | 2c79034534f720bdb60b8f93415e3a838019346f (patch) | |
tree | 02f9cf8e58e8eee527125cf13839a471ac7a658d /src/job | |
parent | 786c9e5f9288f520f680ab4b00433afabbcf007c (diff) |
Implement artifact finding
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/job')
-rw-r--r-- | src/job/runnable.rs | 37 | ||||
-rw-r--r-- | src/job/set.rs | 5 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/job/runnable.rs b/src/job/runnable.rs index 4377d27..0a2bcb2 100644 --- a/src/job/runnable.rs +++ b/src/job/runnable.rs @@ -1,6 +1,10 @@ use getset::Getters; use uuid::Uuid; +use anyhow::anyhow; +use anyhow::Context; +use anyhow::Error; use anyhow::Result; +use resiter::Map; use crate::job::Job; use crate::job::JobResource; @@ -9,6 +13,8 @@ use crate::package::Script; use crate::package::ScriptBuilder; use crate::phase::PhaseName; use crate::util::docker::ImageName; +use crate::filestore::MergedStores; +use crate::package::ParseDependency; /// A job configuration that can be run. All inputs are clear here. #[derive(Debug, Getters)] @@ -29,15 +35,42 @@ pub struct RunnableJob { } impl RunnableJob { - pub fn build_from_job(job: Job) -> Result<Self> { + pub fn build_from_job<'a>(job: Job, merged_stores: &'a MergedStores<'a>) -> Result<Self> { let script = ScriptBuilder::new(&job.script_shebang) .build(&job.package, &job.script_phases)?; + let resources = job.package() + .dependencies() + .build() + .into_iter() + .map(|runtime_dep| { + let (name, version) = runtime_dep.parse_as_name_and_version()?; + let mut a = merged_stores.get_artifact_by_name_and_version(&name, &version); + + if a.is_empty() { + Err(anyhow!("Cannot find dependency: {:?} {:?}", name, version)) + .context("Building a runnable job") + .map_err(Error::from) + } else { + a.sort(); + let a_len = a.len(); + let found_dependency = a.into_iter().next().unwrap(); // save by above check + if a_len > 1 { + warn!("Found more than one dependency for {:?} {:?}", name, version); + warn!("Using: {:?}", found_dependency); + warn!("Please investigate, this might be a BUG"); + } + + Ok(JobResource::Artifact(found_dependency.clone())) + } + }) + .collect::<Result<Vec<JobResource>>>()?; + Ok(RunnableJob { uuid: job.uuid, package: job.package, image: job.image, - resources: job.resources, + resources: job.resources.into_iter().chain(resources.into_iter()).collect(), script, }) diff --git a/src/job/set.rs b/src/job/set.rs index 9b40fd7..a89c352 100644 --- a/src/job/set.rs +++ b/src/job/set.rs @@ -6,6 +6,7 @@ use crate::package::Tree; use crate::phase::PhaseName; use crate::util::docker::ImageName; use crate::job::RunnableJob; +use crate::filestore::MergedStores; /// A set of jobs that could theoretically be run in parallel #[derive(Debug)] @@ -22,8 +23,8 @@ impl JobSet { self.set.is_empty() } - pub fn into_runables(self) -> impl Iterator<Item = Result<RunnableJob>> { - self.set.into_iter().map(RunnableJob::build_from_job) + pub fn into_runables<'a>(self, merged_stores: &'a MergedStores<'a>) -> impl Iterator<Item = Result<RunnableJob>> + 'a { + self.set.into_iter().map(move |j| RunnableJob::build_from_job(j, merged_stores)) } } |