Browse Source

Implement pausing section runner from MQTT

master
Alex Mikhalev 4 years ago
parent
commit
c7941372bf
  1. 2
      src/mqtt/request/mod.rs
  2. 36
      src/mqtt/request/sections.rs

2
src/mqtt/request/mod.rs

@ -257,6 +257,7 @@ pub enum Request { @@ -257,6 +257,7 @@ pub enum Request {
RunSection(sections::RunSectionRequest),
CancelSection(sections::CancelSectionRequest),
CancelSectionRunId(sections::CancelSectionRunIdRequest),
PauseSectionRunner(sections::PauseSectionRunnerRequest),
}
impl IRequest for Request {
@ -267,6 +268,7 @@ impl IRequest for Request { @@ -267,6 +268,7 @@ impl IRequest for Request {
Request::RunSection(req) => req.exec_erased(ctx),
Request::CancelSection(req) => req.exec_erased(ctx),
Request::CancelSectionRunId(req) => req.exec_erased(ctx),
Request::PauseSectionRunner(req) => req.exec_erased(ctx),
}
}
}

36
src/mqtt/request/sections.rs

@ -121,3 +121,39 @@ impl IRequest for CancelSectionRunIdRequest { @@ -121,3 +121,39 @@ impl IRequest for CancelSectionRunIdRequest {
})
}
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PauseSectionRunnerRequest {
pub paused: bool,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PauseSectionRunnerResponse {
pub message: String,
pub paused: bool,
}
impl IRequest for PauseSectionRunnerRequest {
type Response = PauseSectionRunnerResponse;
fn exec(&mut self, ctx: &mut RequestContext) -> RequestFuture<Self::Response> {
let mut section_runner = ctx.section_runner.clone();
let paused = self.paused;
Box::pin(async move {
if paused {
section_runner.pause().await
} else {
section_runner.unpause().await
}
.wrap_err("could not pause/unpause section runner")?;
Ok(PauseSectionRunnerResponse {
message: format!(
"{} section runner",
if paused { "paused" } else { "unpaused" }
),
paused,
})
})
}
}

Loading…
Cancel
Save