diff --git a/src/mqtt/request/mod.rs b/src/mqtt/request/mod.rs index 2dd460f..ae367db 100644 --- a/src/mqtt/request/mod.rs +++ b/src/mqtt/request/mod.rs @@ -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), } } } diff --git a/src/mqtt/request/sections.rs b/src/mqtt/request/sections.rs index ca222f4..e86d23c 100644 --- a/src/mqtt/request/sections.rs +++ b/src/mqtt/request/sections.rs @@ -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 { + 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, + }) + }) + } +}