From a56da9b9e08e6b83026a92df8c4f5ceda44360cc Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Fri, 18 Sep 2020 16:03:26 -0600 Subject: [PATCH] Add schedule fields to program --- src/model/program.rs | 3 ++ src/program_runner.rs | 80 ++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/model/program.rs b/src/model/program.rs index c76f8a4..9a13a77 100644 --- a/src/model/program.rs +++ b/src/model/program.rs @@ -1,5 +1,6 @@ use std::{time::Duration, sync::Arc}; use super::section::SectionId; +use crate::schedule::Schedule; #[derive(Debug, Clone)] pub struct ProgramItem { @@ -16,6 +17,8 @@ pub struct Program { pub id: ProgramId, pub name: String, pub sequence: ProgramSequence, + pub enabled: bool, + pub schedule: Schedule, } pub type ProgramRef = Arc; diff --git a/src/program_runner.rs b/src/program_runner.rs index 9acda05..b671cfc 100644 --- a/src/program_runner.rs +++ b/src/program_runner.rs @@ -373,6 +373,7 @@ mod test { use crate::section_interface::{MockSectionInterface, SectionInterface}; use crate::{ model::{Program, ProgramItem, Section}, + schedule::Schedule, trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, }; use im::ordmap; @@ -428,6 +429,17 @@ mod test { (sections, sec_runner, interface) } + fn make_program(num: ProgramId, sequence: Vec) -> ProgramRef { + Program { + id: num, + name: format!("Program {}", num), + sequence, + enabled: false, + schedule: Schedule::default(), + } + .into() + } + #[tokio::test] async fn test_run_program() { let (sections, mut sec_runner, interface) = make_sections_and_runner(); @@ -435,10 +447,9 @@ mod test { let mut runner = ProgramRunner::new(sec_runner.clone()); let mut prog_events = runner.subscribe().await.unwrap(); - let program: ProgramRef = Program { - id: 1, - name: "Program 1".into(), - sequence: vec![ + let program = make_program( + 1, + vec![ ProgramItem { section_id: 1, duration: Duration::from_secs(10), @@ -448,8 +459,7 @@ mod test { duration: Duration::from_secs(10), }, ], - } - .into(); + ); runner.update_sections(sections.clone()).await.unwrap(); @@ -497,25 +507,20 @@ mod test { let mut runner = ProgramRunner::new(sec_runner.clone()); let mut prog_events = runner.subscribe().await.unwrap(); - let program1: ProgramRef = Program { - id: 1, - name: "Program 1".into(), - sequence: vec![ProgramItem { + let program1 = make_program( + 1, + vec![ProgramItem { section_id: 3, duration: Duration::from_secs(10), }], - } - .into(); - let program2: ProgramRef = Program { - id: 2, - name: "Program 2".into(), - sequence: vec![ProgramItem { + ); + let program2 = make_program( + 2, + vec![ProgramItem { section_id: 1, duration: Duration::from_secs(10), }], - } - .into(); - + ); runner.update_sections(sections.clone()).await.unwrap(); runner.run_program(program1).await.unwrap(); @@ -559,12 +564,7 @@ mod test { let mut runner = ProgramRunner::new(sec_runner.clone()); let mut prog_events = runner.subscribe().await.unwrap(); - let program: ProgramRef = Program { - id: 1, - name: "Program 1".into(), - sequence: vec![], - } - .into(); + let program = make_program(1, vec![]); runner.update_sections(sections.clone()).await.unwrap(); @@ -588,24 +588,20 @@ mod test { let mut runner = ProgramRunner::new(sec_runner.clone()); let mut prog_events = runner.subscribe().await.unwrap(); - let program1: ProgramRef = Program { - id: 1, - name: "Program 1".into(), - sequence: vec![ProgramItem { + let program1 = make_program( + 1, + vec![ProgramItem { section_id: 2, duration: Duration::from_secs(10), }], - } - .into(); - let program2: ProgramRef = Program { - id: 2, - name: "Program 2".into(), - sequence: vec![ProgramItem { + ); + let program2 = make_program( + 2, + vec![ProgramItem { section_id: 2, duration: Duration::from_secs(10), }], - } - .into(); + ); let programs = ordmap![ 1 => program1, 2 => program2 ]; runner.update_sections(sections.clone()).await.unwrap(); @@ -659,10 +655,9 @@ mod test { let mut runner = ProgramRunner::new(sec_runner.clone()); let mut prog_events = runner.subscribe().await.unwrap(); - let program: ProgramRef = Program { - id: 1, - name: "Program 1".into(), - sequence: vec![ + let program = make_program( + 1, + vec![ ProgramItem { section_id: 1, duration: Duration::from_secs(10), @@ -672,8 +667,7 @@ mod test { duration: Duration::from_secs(10), }, ], - } - .into(); + ); runner.update_sections(sections.clone()).await.unwrap();