From bb3c0d3972f161a92d610230fe0466ccc505a3da Mon Sep 17 00:00:00 2001 From: Kinesin Data Technologies Incorporated <93931750+kinesintech@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:48:29 -0300 Subject: [PATCH] Adding default provides of the task name --- src/task.rs | 14 ++++++++++---- src/world.rs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/task.rs b/src/task.rs index 035c11d..8cc1d3c 100644 --- a/src/task.rs +++ b/src/task.rs @@ -99,7 +99,7 @@ pub struct TaskDefinition { } impl TaskDefinition { - pub fn to_task(&self, calendar: &Calendar) -> Task { + pub fn to_task(&self, name: &str, calendar: &Calendar) -> Task { let schedule = Schedule::new(calendar.clone(), self.times.clone(), self.timezone); /* The valid_{from,to} interval must be aligned to the actual schedule. @@ -112,6 +112,12 @@ impl TaskDefinition { ) .start; + let provides = if self.provides.is_empty() { + HashSet::from([name.to_owned()]) + } else { + self.provides.clone() + }; + let end = match self.valid_to { Some(nt) => self.timezone.from_local_datetime(&nt).unwrap(), None => MAX_TIME.with_timezone(&self.timezone), @@ -124,7 +130,7 @@ impl TaskDefinition { down: self.down.clone(), check: self.check.clone(), - provides: self.provides.clone(), + provides, requires: self.requires.clone(), schedule: schedule, @@ -393,7 +399,7 @@ mod tests { let cal = Calendar::new(); { let task_def: TaskDefinition = serde_json::from_str(task_json).unwrap(); - let task = task_def.to_task(&cal); + let task = task_def.to_task("task", &cal); // Assert the valid interval is correct assert_eq!( @@ -413,7 +419,7 @@ mod tests { task_def.valid_from = NaiveDate::from_ymd(2022, 1, 1).and_hms(9, 0, 0); task_def.valid_to = Some(NaiveDate::from_ymd(2022, 1, 7).and_hms(17, 0, 0)); - let task = task_def.to_task(&cal); + let task = task_def.to_task("task", &cal); // Assert the valid interval is correct assert_eq!( diff --git a/src/world.rs b/src/world.rs index 205e108..c852038 100644 --- a/src/world.rs +++ b/src/world.rs @@ -32,7 +32,7 @@ impl WorldDefinition { .map(|(tn, td)| { ( tn.clone(), - td.to_task(self.calendars.get(&td.calendar_name).unwrap()), + td.to_task(tn, self.calendars.get(&td.calendar_name).unwrap()), ) }) .collect();