|
|
@ -10,6 +10,7 @@ use tokio::{ |
|
|
|
time::{delay_queue, DelayQueue}, |
|
|
|
time::{delay_queue, DelayQueue}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use tracing::{debug, error, trace, trace_span, warn}; |
|
|
|
use tracing::{debug, error, trace, trace_span, warn}; |
|
|
|
|
|
|
|
use tracing_futures::Instrument; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
enum RunnerMsg { |
|
|
|
enum RunnerMsg { |
|
|
@ -292,7 +293,7 @@ impl RunnerTask { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async fn start_impl(&mut self) -> eyre::Result<()> { |
|
|
|
async fn run_impl(&mut self) -> eyre::Result<()> { |
|
|
|
let mut sec_events = self |
|
|
|
let mut sec_events = self |
|
|
|
.section_runner |
|
|
|
.section_runner |
|
|
|
.subscribe() |
|
|
|
.subscribe() |
|
|
@ -321,11 +322,11 @@ impl RunnerTask { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async fn start(mut self) { |
|
|
|
async fn run(mut self) { |
|
|
|
let span = trace_span!("program_runner::runner_task"); |
|
|
|
let span = trace_span!("program_runner task"); |
|
|
|
let _enter = span.enter(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.start_impl() |
|
|
|
self.run_impl() |
|
|
|
|
|
|
|
.instrument(span) |
|
|
|
.await |
|
|
|
.await |
|
|
|
.expect("error in ProgramRunner task"); |
|
|
|
.expect("error in ProgramRunner task"); |
|
|
|
} |
|
|
|
} |
|
|
@ -358,7 +359,7 @@ pub struct ProgramRunner { |
|
|
|
impl ProgramRunner { |
|
|
|
impl ProgramRunner { |
|
|
|
pub fn new(section_runner: SectionRunner) -> Self { |
|
|
|
pub fn new(section_runner: SectionRunner) -> Self { |
|
|
|
let (msg_send, msg_recv) = mpsc::channel(8); |
|
|
|
let (msg_send, msg_recv) = mpsc::channel(8); |
|
|
|
spawn(RunnerTask::new(section_runner, msg_recv).start()); |
|
|
|
spawn(RunnerTask::new(section_runner, msg_recv).run()); |
|
|
|
Self { msg_send } |
|
|
|
Self { msg_send } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -438,7 +439,7 @@ mod test { |
|
|
|
let task_span = SpanListener::new( |
|
|
|
let task_span = SpanListener::new( |
|
|
|
SpanFilters::new() |
|
|
|
SpanFilters::new() |
|
|
|
.target("sprinklers_rs::program_runner") |
|
|
|
.target("sprinklers_rs::program_runner") |
|
|
|
.name("program_runner::runner_task"), |
|
|
|
.name("program_runner task"), |
|
|
|
); |
|
|
|
); |
|
|
|
let subscriber = tracing_subscriber::registry() |
|
|
|
let subscriber = tracing_subscriber::registry() |
|
|
|
.with(quit_msg.clone()) |
|
|
|
.with(quit_msg.clone()) |
|
|
@ -529,11 +530,20 @@ mod test { |
|
|
|
assert_eq!(interface.get_section_state(0), true); |
|
|
|
assert_eq!(interface.get_section_state(0), true); |
|
|
|
|
|
|
|
|
|
|
|
tokio::time::pause(); |
|
|
|
tokio::time::pause(); |
|
|
|
assert_matches!(sec_events.recv().await.unwrap(), SectionEvent::RunFinish(_, _)); |
|
|
|
assert_matches!( |
|
|
|
assert_matches!(sec_events.recv().await.unwrap(), SectionEvent::RunStart(_, _)); |
|
|
|
sec_events.recv().await.unwrap(), |
|
|
|
|
|
|
|
SectionEvent::RunFinish(_, _) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
assert_matches!( |
|
|
|
|
|
|
|
sec_events.recv().await.unwrap(), |
|
|
|
|
|
|
|
SectionEvent::RunStart(_, _) |
|
|
|
|
|
|
|
); |
|
|
|
assert_eq!(interface.get_section_state(0), false); |
|
|
|
assert_eq!(interface.get_section_state(0), false); |
|
|
|
assert_eq!(interface.get_section_state(1), true); |
|
|
|
assert_eq!(interface.get_section_state(1), true); |
|
|
|
assert_matches!(sec_events.recv().await.unwrap(), SectionEvent::RunFinish(_, _)); |
|
|
|
assert_matches!( |
|
|
|
|
|
|
|
sec_events.recv().await.unwrap(), |
|
|
|
|
|
|
|
SectionEvent::RunFinish(_, _) |
|
|
|
|
|
|
|
); |
|
|
|
assert_matches!( |
|
|
|
assert_matches!( |
|
|
|
prog_events.recv().await.unwrap(), |
|
|
|
prog_events.recv().await.unwrap(), |
|
|
|
ProgramEvent::RunFinish(_) |
|
|
|
ProgramEvent::RunFinish(_) |
|
|
@ -724,7 +734,10 @@ mod test { |
|
|
|
ProgramEvent::RunCancel(prog) |
|
|
|
ProgramEvent::RunCancel(prog) |
|
|
|
if prog.id == 1 |
|
|
|
if prog.id == 1 |
|
|
|
); |
|
|
|
); |
|
|
|
assert_matches!(sec_events.recv().await.unwrap(), SectionEvent::RunCancel(_, _)); |
|
|
|
assert_matches!( |
|
|
|
|
|
|
|
sec_events.recv().await.unwrap(), |
|
|
|
|
|
|
|
SectionEvent::RunCancel(_, _) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
runner.quit().await.unwrap(); |
|
|
|
runner.quit().await.unwrap(); |
|
|
|
sec_runner.quit().await.unwrap(); |
|
|
|
sec_runner.quit().await.unwrap(); |
|
|
|