From fcd4c004f76cc224ddf1f2dfbe0e4e3fc1136f3b Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 27 Sep 2025 11:19:58 +0000 Subject: [PATCH] fix: restore set_progress feature with sse --- backend/windmill-api/src/jobs.rs | 25 +++++++--- frontend/src/lib/components/JobArgs.svelte | 36 +++++++------ frontend/src/lib/components/JobLoader.svelte | 50 +++---------------- .../flows/content/FlowModuleComponent.svelte | 1 - .../lib/components/jobs/JobProgressBar.svelte | 17 +++++-- .../(root)/(logged)/run/[...run]/+page.svelte | 6 ++- 6 files changed, 64 insertions(+), 71 deletions(-) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 10edb6ff94..e370896b52 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -6702,7 +6702,7 @@ async fn get_job_update( &job_id, log_offset, stream_offset, - get_progress, + get_progress.unwrap_or(false), running, true, false, @@ -6806,6 +6806,7 @@ fn start_job_update_sse_stream( // Send initial update immediately let mut running = running; let mut mem_peak = 0; + match get_job_update_data( &opt_authed, &opt_tokened, @@ -6814,7 +6815,7 @@ fn start_job_update_sse_stream( &job_id, log_offset, stream_offset, - get_progress, + false, running, true, true, @@ -6871,11 +6872,12 @@ fn start_job_update_sse_stream( } } + let mut get_progress_m: bool = false; // Poll for updates every 1 second let mut i = 0; let start = Instant::now(); let mut last_ping = Instant::now(); - + let mut last_progress_check = Instant::now(); loop { i += 1; @@ -6918,6 +6920,10 @@ fn start_job_update_sse_stream( } tokio::time::sleep(std::time::Duration::from_millis(ms_duration)).await; + // Check progress if the user requested it, and check periodically if the job has progress + // Once it has progress, we always check progress + let check_progress = get_progress.unwrap_or(false) + && (get_progress_m || last_progress_check.elapsed().as_secs() > 5); match get_job_update_data( &opt_authed, &opt_tokened, @@ -6926,7 +6932,7 @@ fn start_job_update_sse_stream( &job_id, log_offset, stream_offset, - get_progress, + check_progress, running, false, true, @@ -6947,6 +6953,13 @@ fn start_job_update_sse_stream( if update.new_logs.as_ref().is_some_and(|x| x.is_empty()) { update.new_logs = None; } + if check_progress { + if update.progress.is_some() { + get_progress_m = true; + } else { + last_progress_check = Instant::now(); + } + } // if !only_result.unwrap_or(false) { // tracing::error!("update {:?}", update); @@ -7044,7 +7057,7 @@ async fn get_job_update_data( job_id: &Uuid, log_offset: Option, stream_offset: Option, - get_progress: Option, + get_progress: bool, running: Option, log_view: bool, get_full_job_on_completion: bool, @@ -7281,7 +7294,7 @@ async fn get_job_update_data( log_offset, w_id, job_id, - get_progress.unwrap_or(false), + get_progress, running, tags.as_ref().map(|v| v.as_slice()) as Option<&[&str]>, no_logs.unwrap_or(false), diff --git a/frontend/src/lib/components/JobArgs.svelte b/frontend/src/lib/components/JobArgs.svelte index 67435ebc09..00211790bc 100644 --- a/frontend/src/lib/components/JobArgs.svelte +++ b/frontend/src/lib/components/JobArgs.svelte @@ -14,14 +14,18 @@ import { deepEqual } from 'fast-equals' import { isWindmillTooBigObject } from './job_args' - export let id: string | undefined = undefined - export let args: any - export let argLabel: string | undefined = undefined - export let workspace: string | undefined = undefined + interface Props { + id?: string | undefined + args: any + argLabel?: string | undefined + workspace?: string | undefined + } - let jsonViewer: Drawer - let runLocally: Drawer - let jsonStr = '' + let { id = undefined, args, argLabel = undefined, workspace = undefined }: Props = $props() + + let jsonViewer: Drawer | undefined = $state() + let runLocally: Drawer | undefined = $state() + let jsonStr = $state('') function pythonCode() { return ` @@ -53,9 +57,9 @@ ${Object.entries(args) } -{#if args && typeof args === 'object' && deepEqual( Object.keys(args), ['reason'] ) && args['reason'] == 'PREPROCESSOR_ARGS_ARE_DISCARDED'} +{#if args && typeof args === 'object' && deepEqual( Object.keys(args ?? {}), ['reason'] ) && args['reason'] == 'PREPROCESSOR_ARGS_ARE_DISCARDED'} Preprocessor args are discarded -{:else if id && workspace && args && typeof args === 'object' && deepEqual( Object.keys(args), ['reason'] ) && args['reason'] == 'WINDMILL_TOO_BIG'} +{:else if id && workspace && args && typeof args === 'object' && deepEqual( Object.keys(args ?? {}), ['reason'] ) && args['reason'] == 'WINDMILL_TOO_BIG'} The args are too big in size to be able to fetch alongside job. Please download the JSON file to view them{argLabel ?? 'Arg'} Value - + {#snippet headerAction()} - + {/snippet} - {#if args && typeof args === 'object' && Object.keys(args).length > 0} - {#each Object.entries(args).sort((a, b) => a[0].localeCompare(b[0])) as [arg, value]} + {#if args && typeof args === 'object' && Object.keys(args ?? {}).length > 0} + {#each Object.entries(args ?? {}).sort( (a, b) => a?.[0]?.localeCompare(b?.[0]) ) as [arg, value]} {arg} @@ -124,7 +128,7 @@ ${Object.entries(args) Download