Skip to content

Commit

Permalink
Expose the cancel and retry/kill and retry commands in the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Dec 6, 2024
1 parent bdd4b9b commit 2fc253f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 18 additions & 3 deletions cli/src/clients/admin_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ pub trait AdminClientInterface {

async fn purge_invocation(&self, id: &str) -> reqwest::Result<Envelope<()>>;

async fn cancel_invocation(&self, id: &str, kill: bool) -> reqwest::Result<Envelope<()>>;
async fn cancel_invocation(
&self,
id: &str,
kill: bool,
retry: bool,
) -> reqwest::Result<Envelope<()>>;

async fn patch_state(
&self,
Expand Down Expand Up @@ -132,15 +137,25 @@ impl AdminClientInterface for AdminClient {
self.run(reqwest::Method::DELETE, url).await
}

async fn cancel_invocation(&self, id: &str, kill: bool) -> reqwest::Result<Envelope<()>> {
async fn cancel_invocation(
&self,
id: &str,
kill: bool,
retry: bool,
) -> reqwest::Result<Envelope<()>> {
let mut url = self
.base_url
.join(&format!("/invocations/{id}"))
.expect("Bad url!");

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
Expand Down
18 changes: 12 additions & 6 deletions cli/src/commands/invocations/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CliEnv>, opts: &Cancel) -> Result<()> {
Expand Down Expand Up @@ -67,16 +70,19 @@ pub async fn run_cancel(State(env): State<CliEnv>, 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()?;
}

Expand Down

0 comments on commit 2fc253f

Please sign in to comment.