diff --git a/cli/src/clients/admin_interface.rs b/cli/src/clients/admin_interface.rs index 8cf91859d..2fcdbecbd 100644 --- a/cli/src/clients/admin_interface.rs +++ b/cli/src/clients/admin_interface.rs @@ -41,7 +41,12 @@ pub trait AdminClientInterface { async fn purge_invocation(&self, id: &str) -> reqwest::Result>; - async fn cancel_invocation(&self, id: &str, kill: bool) -> reqwest::Result>; + async fn cancel_invocation( + &self, + id: &str, + kill: bool, + retry: bool, + ) -> reqwest::Result>; async fn patch_state( &self, @@ -132,7 +137,12 @@ impl AdminClientInterface for AdminClient { self.run(reqwest::Method::DELETE, url).await } - async fn cancel_invocation(&self, id: &str, kill: bool) -> reqwest::Result> { + async fn cancel_invocation( + &self, + id: &str, + kill: bool, + retry: bool, + ) -> reqwest::Result> { let mut url = self .base_url .join(&format!("/invocations/{id}")) @@ -140,7 +150,12 @@ impl AdminClientInterface for AdminClient { url.set_query(Some(&format!( "mode={}", - if kill { "kill" } else { "cancel" } + match (kill, retry) { + (false, false) => "cancel", + (false, true) => "cancel-and-restart", + (true, false) => "kill", + (true, true) => "kill-and-restart", + } ))); self.run(reqwest::Method::DELETE, url).await diff --git a/cli/src/commands/invocations/cancel.rs b/cli/src/commands/invocations/cancel.rs index 8cd8586e0..d026811e5 100644 --- a/cli/src/commands/invocations/cancel.rs +++ b/cli/src/commands/invocations/cancel.rs @@ -37,6 +37,9 @@ pub struct Cancel { /// Ungracefully kill the invocation and its children #[clap(long)] kill: bool, + /// After cancelling/killing, restart the invocation using the same input. + #[clap(long, alias = "retry")] + restart: bool, } pub async fn run_cancel(State(env): State, opts: &Cancel) -> Result<()> { @@ -67,16 +70,19 @@ pub async fn run_cancel(State(env): State, opts: &Cancel) -> Result<()> // Get the invocation and confirm let prompt = format!( "Are you sure you want to {} these invocations?", - if opts.kill { - Styled(Style::Danger, "kill") - } else { - Styled(Style::Warn, "cancel") - }, + match (opts.kill, opts.restart) { + (false, false) => Styled(Style::Warn, "cancel"), + (false, true) => Styled(Style::Warn, "cancel and restart"), + (true, false) => Styled(Style::Danger, "kill"), + (true, true) => Styled(Style::Danger, "kill and restart"), + } ); confirm_or_exit(&prompt)?; for inv in invocations { - let result = client.cancel_invocation(&inv.id, opts.kill).await?; + let result = client + .cancel_invocation(&inv.id, opts.kill, opts.restart) + .await?; let _ = result.success_or_error()?; }