Implement pausing section runner from MQTT
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex Mikhalev 2020-09-30 14:13:06 -06:00
parent 2ad00b4b69
commit c7941372bf
2 changed files with 38 additions and 0 deletions

View File

@ -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 {
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),
}
}
}

View File

@ -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,
})
})
}
}