Alex Mikhalev
4 years ago
3 changed files with 39 additions and 1 deletions
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
use super::*; |
||||
use crate::{model::ProgramId, program_runner::ProgramRunnerError}; |
||||
use eyre::WrapErr; |
||||
|
||||
#[derive(Debug, Serialize, Deserialize)] |
||||
#[serde(rename_all = "camelCase")] |
||||
pub struct RunProgramRequest { |
||||
program_id: ProgramId, |
||||
} |
||||
|
||||
impl IRequest for RunProgramRequest { |
||||
type Response = ResponseMessage; |
||||
|
||||
fn exec(&mut self, ctx: &mut RequestContext) -> RequestFuture<Self::Response> { |
||||
let mut program_runner = ctx.program_runner.clone(); |
||||
let program_id = self.program_id; |
||||
Box::pin(async move { |
||||
match program_runner.run_program_id(program_id).await { |
||||
Ok(program) => Ok(ResponseMessage::new(format!( |
||||
"running program '{}'", |
||||
program.name |
||||
))), |
||||
Err(e @ ProgramRunnerError::InvalidProgramId(_)) => Err(RequestError::with_name( |
||||
ErrorCode::NoSuchProgram, |
||||
e, |
||||
"program", |
||||
)), |
||||
Err(e) => Err(e).wrap_err("could not run program")?, |
||||
} |
||||
}) |
||||
} |
||||
} |
Loading…
Reference in new issue