From 19156251f259c5c8474c8386ca498044917dd377 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Wed, 24 Jun 2026 18:09:51 +0200 Subject: [PATCH] Implement a --wait option for job-start Starts a job and follows the log in the foreground --- src/cli/cmd/job/logs.rs | 22 +++++++--------------- src/cli/cmd/job/start.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/cli/cmd/job/logs.rs b/src/cli/cmd/job/logs.rs index 5946f64..2fd359b 100644 --- a/src/cli/cmd/job/logs.rs +++ b/src/cli/cmd/job/logs.rs @@ -38,19 +38,15 @@ pub enum Error { impl Input { pub async fn exec(&self, ctx: Context) -> Result<(), Error> { if self.follow { - self.follow_logs(ctx).await + self.follow_logs(ctx).await.context(HttpClientSnafu) } else { - self.show_logs(&ctx, 0).await?; + self.show_logs(&ctx, 0).await.context(HttpClientSnafu)?; Ok(()) } } - async fn show_logs(&self, ctx: &Context, seen: usize) -> Result { - let result = ctx - .client - .session_logs(&self.job_id) - .await - .context(HttpClientSnafu)?; + async fn show_logs(&self, ctx: &Context, seen: usize) -> Result { + let result = ctx.client.session_logs(&self.job_id).await?; if let Some(lines_blob) = result.0.get("amalthea-session") { let lines: Vec<&str> = lines_blob.lines().collect(); if lines.len() > seen { @@ -63,12 +59,8 @@ impl Input { Ok(seen) } - async fn is_session_finished(&self, ctx: &Context) -> Result { - let details = ctx - .client - .get_session(&self.job_id) - .await - .context(HttpClientSnafu)?; + async fn is_session_finished(&self, ctx: &Context) -> Result { + let details = ctx.client.get_session(&self.job_id).await?; match &details { None => Ok(true), @@ -76,7 +68,7 @@ impl Input { } } - async fn follow_logs(&self, ctx: Context) -> Result<(), Error> { + pub async fn follow_logs(&self, ctx: Context) -> Result<(), httpclient::Error> { let mut seen: usize = self.show_logs(&ctx, 0).await?; if self.is_session_finished(&ctx).await? { return Ok(()); diff --git a/src/cli/cmd/job/start.rs b/src/cli/cmd/job/start.rs index 09d7896..d17f758 100644 --- a/src/cli/cmd/job/start.rs +++ b/src/cli/cmd/job/start.rs @@ -1,6 +1,6 @@ use crate::{ - cli::complete::complete_job_launcher_id, - data::submission_id::SubmissionId, + cli::{cmd::job::logs, complete::complete_job_launcher_id}, + data::{simple_message::SimpleMessage, submission_id::SubmissionId}, httpclient::{self, data::SessionStartRequest}, }; @@ -33,6 +33,10 @@ pub struct Input { #[arg(long)] pub command: Vec, + /// Start the job and show the logs until it ends or the user cancels with Ctrl-C. + #[arg(long, default_value_t = false)] + pub wait: bool, + /// These arguments are passed to the renku job command. #[arg(trailing_var_arg = true, allow_hyphen_values = true, num_args = 0.., value_name = "ARGS")] pub passthrough: Vec, @@ -76,6 +80,24 @@ impl Input { .await .context(HttpClientSnafu)?; - ctx.write_result(&result).await.context(WriteResultSnafu) + if self.wait { + ctx.write_result(&SimpleMessage { + message: format!( + "Started job {} (submission_id: {}). Waiting for logs...", + result.name, + result.submission_id.unwrap_or("-".to_string()) + ), + }) + .await + .context(WriteResultSnafu)?; + let log_input = logs::Input { + job_id: result.name, + follow: true, + follow_interval: 2, + }; + log_input.follow_logs(ctx).await.context(HttpClientSnafu) + } else { + ctx.write_result(&result).await.context(WriteResultSnafu) + } } }