diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-10-22 18:27:09 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-10-26 15:31:44 +0100 |
commit | 1dd65c869c8ca3511a430ec6981f1d83bb8d787e (patch) | |
tree | 04ed498b69394a53a74eb6e9de337dee5e6579a2 /src/job | |
parent | adaad3a4c1665bbfe74875b3dd4bdf51ca05adca (diff) |
Add job related types
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/job')
-rw-r--r-- | src/job/job.rs | 44 | ||||
-rw-r--r-- | src/job/mod.rs | 12 | ||||
-rw-r--r-- | src/job/resource.rs | 9 | ||||
-rw-r--r-- | src/job/runnable.rs | 46 | ||||
-rw-r--r-- | src/job/set.rs | 4 |
5 files changed, 115 insertions, 0 deletions
diff --git a/src/job/job.rs b/src/job/job.rs new file mode 100644 index 0000000..72a86aa --- /dev/null +++ b/src/job/job.rs @@ -0,0 +1,44 @@ +use uuid::Uuid; + +use crate::job::JobResource; +use crate::package::Package; +use crate::phase::PhaseName; +use crate::util::docker::ImageName; + +/// A prepared, but not necessarily runnable, job configuration +#[derive(Debug)] +pub struct Job { + /// A unique name for the job, not necessarily human-readable + pub(in super) uuid: Uuid, + + pub(in super) package: Package, + pub(in super) image: ImageName, + + pub(in super) script_shebang: String, + pub(in super) script_phases: Vec<PhaseName>, + + pub(in super) resources: Vec<JobResource>, +} + +impl Job { + + pub fn new(pkg: Package, image: ImageName, phases: Vec<PhaseName>) -> Self { + let uuid = Uuid::new_v4(); + + Job { + uuid, + package: pkg, + image, + script_shebang: String::from("#!/bin/bash"), // TODO Dont hardcode + script_phases: phases, + resources: Vec::new(), + } + + } + + pub fn add_resource(&mut self, res: JobResource) { + self.resources.push(res) + } + +} + diff --git a/src/job/mod.rs b/src/job/mod.rs new file mode 100644 index 0000000..718a2b1 --- /dev/null +++ b/src/job/mod.rs @@ -0,0 +1,12 @@ +mod job; +pub use job::*; + +mod set; +pub use set::*; + +mod resource; +pub use resource::*; + +mod runnable; +pub use runnable::*; + diff --git a/src/job/resource.rs b/src/job/resource.rs new file mode 100644 index 0000000..03c20d5 --- /dev/null +++ b/src/job/resource.rs @@ -0,0 +1,9 @@ +use std::path::PathBuf; + +/// TODO implement +#[derive(Debug)] +pub enum JobResource { + Environment(String, String), + Path(PathBuf) +} + diff --git a/src/job/runnable.rs b/src/job/runnable.rs new file mode 100644 index 0000000..4377d27 --- /dev/null +++ b/src/job/runnable.rs @@ -0,0 +1,46 @@ +use getset::Getters; +use uuid::Uuid; +use anyhow::Result; + +use crate::job::Job; +use crate::job::JobResource; +use crate::package::Package; +use crate::package::Script; +use crate::package::ScriptBuilder; +use crate::phase::PhaseName; +use crate::util::docker::ImageName; + +/// A job configuration that can be run. All inputs are clear here. +#[derive(Debug, Getters)] +pub struct RunnableJob { + uuid: Uuid, + + #[getset(get = "pub")] + package: Package, + + #[getset(get = "pub")] + image: ImageName, + + #[getset(get = "pub")] + script: Script, + + #[getset(get = "pub")] + resources: Vec<JobResource>, +} + +impl RunnableJob { + pub fn build_from_job(job: Job) -> Result<Self> { + let script = ScriptBuilder::new(&job.script_shebang) + .build(&job.package, &job.script_phases)?; + + Ok(RunnableJob { + uuid: job.uuid, + package: job.package, + image: job.image, + resources: job.resources, + + script, + }) + + } +} diff --git a/src/job/set.rs b/src/job/set.rs new file mode 100644 index 0000000..6a1f8ca --- /dev/null +++ b/src/job/set.rs @@ -0,0 +1,4 @@ +/// A set of jobs that could theoretically be run in parallel +#[derive(Debug)] +pub struct JobSet { +} |