xnode_manager_sdk/process/
handlers.rs

1use crate::{
2    process::models::{Log, LogQuery, Process, ProcessCommand},
3    request::RequestIdResponse,
4    utils::{
5        Empty, SessionGetInput, SessionGetOutput, SessionPostInput, SessionPostOutput, session_get,
6        session_post,
7    },
8};
9
10pub fn scope() -> String {
11    "/process".to_string()
12}
13
14#[derive(Debug, Clone, PartialEq)]
15pub struct ListPath {
16    pub scope: String,
17}
18pub type ListInput<'a> = SessionGetInput<'a, ListPath, Empty>;
19pub type ListOutput = Vec<Process>;
20pub async fn list(input: ListInput<'_>) -> SessionGetOutput<ListOutput> {
21    session_get(input, scope(), |path| {
22        format!("/{scope}/list", scope = path.scope)
23    })
24    .await
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub struct LogsPath {
29    pub scope: String,
30    pub process: String,
31}
32pub type LogsInput<'a> = SessionGetInput<'a, LogsPath, LogQuery>;
33pub type LogsOutput = Vec<Log>;
34pub async fn logs(input: LogsInput<'_>) -> SessionGetOutput<LogsOutput> {
35    session_get(input, scope(), |path| {
36        format!(
37            "/{scope}/{process}/logs",
38            scope = path.scope,
39            process = path.process
40        )
41    })
42    .await
43}
44
45#[derive(Debug, Clone, PartialEq)]
46pub struct ExecutePath {
47    pub scope: String,
48    pub process: String,
49}
50pub type ExecuteInput<'a> = SessionPostInput<'a, ExecutePath, ProcessCommand>;
51pub type ExecuteOutput = RequestIdResponse;
52pub async fn execute(input: ExecuteInput<'_>) -> SessionPostOutput<ExecuteOutput> {
53    session_post(input, scope(), |path| {
54        format!(
55            "/{scope}/{process}/execute",
56            scope = path.scope,
57            process = path.process
58        )
59    })
60    .await
61}