Adding runner and world definition

This commit is contained in:
Kinesin Data Technologies Incorporated
2022-10-03 16:27:43 -03:00
parent 5d0ec03804
commit 2dcb2203e5
9 changed files with 548 additions and 81 deletions
+45
View File
@@ -0,0 +1,45 @@
use super::*;
// A struct used for serializing / deserializing world
#[derive(Debug, Serialize, Deserialize)]
pub struct WorldDefinition {
pub tasks: HashMap<String, TaskDefinition>,
pub calendars: HashMap<String, Calendar>,
#[serde(default)]
pub variables: VarMap,
#[serde(default)]
pub output_options: TaskOutputOptions,
}
impl WorldDefinition {
pub fn taskset(&self) -> Result<TaskSet> {
// Ensure all tasks reference a valid calendar
for (name, def) in self.tasks.iter() {
if !self.calendars.contains_key(&def.calendar_name) {
return Err(anyhow!(
"Task {} references calendar {}, which is not defined",
name,
def.calendar_name
));
}
}
let tasks: HashMap<String, Task> = self
.tasks
.iter()
.map(|(tn, td)| {
(
tn.clone(),
td.to_task(self.calendars.get(&td.calendar_name).unwrap()),
)
})
.collect();
let ts = TaskSet::from(tasks);
ts.validate()?;
Ok(ts)
}
}