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 @@ @@ -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 { @@ -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<Program>;

80
src/program_runner.rs

@ -373,6 +373,7 @@ mod test { @@ -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 { @@ -428,6 +429,17 @@ mod test {
(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]
async fn test_run_program() {
let (sections, mut sec_runner, interface) = make_sections_and_runner();
@ -435,10 +447,9 @@ mod test { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -672,8 +667,7 @@ mod test {
duration: Duration::from_secs(10),
},
],
}
.into();
);
runner.update_sections(sections.clone()).await.unwrap();

Loading…
Cancel
Save