diff --git a/Cargo.toml b/Cargo.toml index 746afa561c12242f927ac58c5ba5f093e66fb894..aba0b3ce712f7619eb78d1082834de41b26ee82e 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 585506fa2176eb84ea1dd8aaa54052599ba50631..384b26098740ad76213619ffed1dbf1d5e331279 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 0db5f49349e9bdd6e69f03243c9ba03580a50280..d34660bb5939f8f5720c488b36aedb17380b1171 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 008fddff2c5e9152230a20320d6ee690cd67729b..cbd85423af78f281a9078dda1c2512aaa884f0f6 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 b028828ba07d90aae592431a9ad4ba94797fecae..2cf3f3b8c5ba73414db91abc39bf417a72642b51 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 e31ca2a7b2c13dfe41199ff1b2e6fd1dea4c9f9d..1cfb78f964059d49248bded80f6a87354f27b8e9 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 + + )} +