Browse Source

Add schedule fields to program

master
Alex Mikhalev 4 years ago
parent
commit
a56da9b9e0
  1. 3
      src/model/program.rs
  2. 80
      src/program_runner.rs

3
src/model/program.rs

@ -1,5 +1,6 @@
use std::{time::Duration, sync::Arc}; use std::{time::Duration, sync::Arc};
use super::section::SectionId; use super::section::SectionId;
use crate::schedule::Schedule;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ProgramItem { pub struct ProgramItem {
@ -16,6 +17,8 @@ pub struct Program {
pub id: ProgramId, pub id: ProgramId,
pub name: String, pub name: String,
pub sequence: ProgramSequence, pub sequence: ProgramSequence,
pub enabled: bool,
pub schedule: Schedule,
} }
pub type ProgramRef = Arc<Program>; pub type ProgramRef = Arc<Program>;

80
src/program_runner.rs

@ -373,6 +373,7 @@ mod test {
use crate::section_interface::{MockSectionInterface, SectionInterface}; use crate::section_interface::{MockSectionInterface, SectionInterface};
use crate::{ use crate::{
model::{Program, ProgramItem, Section}, model::{Program, ProgramItem, Section},
schedule::Schedule,
trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, trace_listeners::{EventListener, Filters, SpanFilters, SpanListener},
}; };
use im::ordmap; use im::ordmap;
@ -428,6 +429,17 @@ mod test {
(sections, sec_runner, interface) (sections, sec_runner, interface)
} }
fn make_program(num: ProgramId, sequence: Vec<ProgramItem>) -> ProgramRef {
Program {
id: num,
name: format!("Program {}", num),
sequence,
enabled: false,
schedule: Schedule::default(),
}
.into()
}
#[tokio::test] #[tokio::test]
async fn test_run_program() { async fn test_run_program() {
let (sections, mut sec_runner, interface) = make_sections_and_runner(); 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 runner = ProgramRunner::new(sec_runner.clone());
let mut prog_events = runner.subscribe().await.unwrap(); let mut prog_events = runner.subscribe().await.unwrap();
let program: ProgramRef = Program { let program = make_program(
id: 1, 1,
name: "Program 1".into(), vec![
sequence: vec![
ProgramItem { ProgramItem {
section_id: 1, section_id: 1,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
@ -448,8 +459,7 @@ mod test {
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}, },
], ],
} );
.into();
runner.update_sections(sections.clone()).await.unwrap(); runner.update_sections(sections.clone()).await.unwrap();
@ -497,25 +507,20 @@ mod test {
let mut runner = ProgramRunner::new(sec_runner.clone()); let mut runner = ProgramRunner::new(sec_runner.clone());
let mut prog_events = runner.subscribe().await.unwrap(); let mut prog_events = runner.subscribe().await.unwrap();
let program1: ProgramRef = Program { let program1 = make_program(
id: 1, 1,
name: "Program 1".into(), vec![ProgramItem {
sequence: vec![ProgramItem {
section_id: 3, section_id: 3,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}], }],
} );
.into(); let program2 = make_program(
let program2: ProgramRef = Program { 2,
id: 2, vec![ProgramItem {
name: "Program 2".into(),
sequence: vec![ProgramItem {
section_id: 1, section_id: 1,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}], }],
} );
.into();
runner.update_sections(sections.clone()).await.unwrap(); runner.update_sections(sections.clone()).await.unwrap();
runner.run_program(program1).await.unwrap(); runner.run_program(program1).await.unwrap();
@ -559,12 +564,7 @@ mod test {
let mut runner = ProgramRunner::new(sec_runner.clone()); let mut runner = ProgramRunner::new(sec_runner.clone());
let mut prog_events = runner.subscribe().await.unwrap(); let mut prog_events = runner.subscribe().await.unwrap();
let program: ProgramRef = Program { let program = make_program(1, vec![]);
id: 1,
name: "Program 1".into(),
sequence: vec![],
}
.into();
runner.update_sections(sections.clone()).await.unwrap(); runner.update_sections(sections.clone()).await.unwrap();
@ -588,24 +588,20 @@ mod test {
let mut runner = ProgramRunner::new(sec_runner.clone()); let mut runner = ProgramRunner::new(sec_runner.clone());
let mut prog_events = runner.subscribe().await.unwrap(); let mut prog_events = runner.subscribe().await.unwrap();
let program1: ProgramRef = Program { let program1 = make_program(
id: 1, 1,
name: "Program 1".into(), vec![ProgramItem {
sequence: vec![ProgramItem {
section_id: 2, section_id: 2,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}], }],
} );
.into(); let program2 = make_program(
let program2: ProgramRef = Program { 2,
id: 2, vec![ProgramItem {
name: "Program 2".into(),
sequence: vec![ProgramItem {
section_id: 2, section_id: 2,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}], }],
} );
.into();
let programs = ordmap![ 1 => program1, 2 => program2 ]; let programs = ordmap![ 1 => program1, 2 => program2 ];
runner.update_sections(sections.clone()).await.unwrap(); runner.update_sections(sections.clone()).await.unwrap();
@ -659,10 +655,9 @@ mod test {
let mut runner = ProgramRunner::new(sec_runner.clone()); let mut runner = ProgramRunner::new(sec_runner.clone());
let mut prog_events = runner.subscribe().await.unwrap(); let mut prog_events = runner.subscribe().await.unwrap();
let program: ProgramRef = Program { let program = make_program(
id: 1, 1,
name: "Program 1".into(), vec![
sequence: vec![
ProgramItem { ProgramItem {
section_id: 1, section_id: 1,
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
@ -672,8 +667,7 @@ mod test {
duration: Duration::from_secs(10), duration: Duration::from_secs(10),
}, },
], ],
} );
.into();
runner.update_sections(sections.clone()).await.unwrap(); runner.update_sections(sections.clone()).await.unwrap();

Loading…
Cancel
Save