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