From 4711d2da9d6defaecf9c01cd8dff6eae1ccbc3f1 Mon Sep 17 00:00:00 2001 From: wHoIsDReAmer Date: Mon, 1 Jul 2024 12:45:14 +0900 Subject: [PATCH] feat: add flush controller on daemon and UI - Change codegen-units size to 16 --- Cargo.toml | 2 +- src/daemon/api/routes.rs | 4 ++++ src/main.rs | 4 ++-- src/process/http.rs | 7 +++++++ src/process/mod.rs | 14 ++++++++++---- src/webui/src/components/react/view.tsx | 9 +++++++++ 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 746afa5..aba0b3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ description = "PMC is a simple and easy to use PM2 alternative" [profile.release] lto = true -codegen-units = 1 +codegen-units = 16 opt-level = "z" panic = "abort" diff --git a/src/daemon/api/routes.rs b/src/daemon/api/routes.rs index 585506f..384b260 100644 --- a/src/daemon/api/routes.rs +++ b/src/daemon/api/routes.rs @@ -759,6 +759,10 @@ pub async fn action_handler(id: usize, body: Json, _t: Token) -> Res timer.observe_duration(); Ok(Json(attempt(true, method))) } + "flush" => { + runner.flush(id); + Ok(Json(attempt(true, method))) + }, _ => { timer.observe_duration(); Err(not_found("Process was not found")) diff --git a/src/main.rs b/src/main.rs index 0db5f49..d34660b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,7 @@ enum Commands { }, /// Stop then remove a process - #[command(visible_alias = "rm")] + #[command(visible_alias = "rm", visible_alias = "delete")] Remove { #[clap(value_parser = cli::validate::)] item: Item, @@ -182,7 +182,7 @@ enum Commands { }, /// Flush a process log - #[command(visible_alias = "flush")] + #[command(visible_alias = "fl")] Flush { #[clap(value_parser = cli::validate::)] item: Item, diff --git a/src/process/http.rs b/src/process/http.rs index 008fddf..cbd8542 100644 --- a/src/process/http.rs +++ b/src/process/http.rs @@ -99,3 +99,10 @@ pub fn remove(Remote { address, token, .. }: &Remote, id: usize) -> Result Result { + let (client, headers) = sync::client(token); + let content = ActionBody { method: string!("flush") }; + + Ok(client.post(fmtstr!("{address}/process/{id}/action")).json(&content).headers(headers).send()?) +} \ No newline at end of file diff --git a/src/process/mod.rs b/src/process/mod.rs index b028828..2cf3f3b 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -508,10 +508,16 @@ impl Runner { } pub fn flush(&mut self, id: usize) -> &mut Self { - match self.info(id) { - Some(item) => item.logs().flush(), - None => crashln!("{} Process ({id}) not found", *helpers::FAIL), - }; + if let Some(remote) = &self.remote { + if let Err(err) = http::flush(remote, id) { + crashln!("{} Failed to flush process {id}\nError: {:#?}", *helpers::FAIL, err); + }; + } else { + match self.info(id) { + Some(item) => item.logs().flush(), + None => crashln!("{} Process ({id}) not found", *helpers::FAIL), + }; + } self } diff --git a/src/webui/src/components/react/view.tsx b/src/webui/src/components/react/view.tsx index e31ca2a..1cfb78f 100644 --- a/src/webui/src/components/react/view.tsx +++ b/src/webui/src/components/react/view.tsx @@ -339,6 +339,15 @@ const View = (props: { id: string; base: string }) => { {({ focus }) => } + + {({ _ }) => ( + action(props.id, 'flush')} + className="text-zinc-200 rounded-md block p-2 w-full text-left cursor-pointer hover:bg-zinc-800/80 hover:text-zinc-50"> + Flush + + )} +
-- GitLab