From d13a357b2609a8ee4f3fac43f248eede3f8ad38d Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 2 Jul 2024 17:54:19 +0200 Subject: [PATCH] feat: allow downloading args over the size limit --- ...7f5033b9c9afc344d9c3e385ba20a3ad2197a.json | 2 +- backend/windmill-api/openapi.yaml | 17 +++ backend/windmill-api/src/jobs.rs | 53 +++++++++ .../components/FlowStatusViewerInner.svelte | 14 ++- frontend/src/lib/components/JobArgs.svelte | 103 ++++++++++-------- frontend/src/lib/components/RunForm.svelte | 13 ++- .../apps/editor/AppEditorHeader.svelte | 6 +- .../src/lib/components/jobs/JobPreview.svelte | 13 ++- .../src/lib/components/runs/JobPreview.svelte | 6 +- .../(logged)/flows/get/[...path]/+page.svelte | 1 - .../(root)/(logged)/run/[...run]/+page.svelte | 6 +- .../scripts/get/[...hash]/+page.svelte | 1 - .../[job]/[resume]/[hmac]/+page.svelte | 6 +- 13 files changed, 184 insertions(+), 57 deletions(-) diff --git a/backend/.sqlx/query-661f472ff3860983322162420457f5033b9c9afc344d9c3e385ba20a3ad2197a.json b/backend/.sqlx/query-661f472ff3860983322162420457f5033b9c9afc344d9c3e385ba20a3ad2197a.json index 1fa370e682..75b8108281 100644 --- a/backend/.sqlx/query-661f472ff3860983322162420457f5033b9c9afc344d9c3e385ba20a3ad2197a.json +++ b/backend/.sqlx/query-661f472ff3860983322162420457f5033b9c9afc344d9c3e385ba20a3ad2197a.json @@ -5,7 +5,7 @@ "columns": [ { "ordinal": 0, - "name": "bool", + "name": "?column?", "type_info": "Bool" } ], diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 9f475e814f..2f1dc3a32b 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -5718,6 +5718,23 @@ paths: schema: type: string + + /w/{workspace}/jobs_u/get_args/{id}: + get: + summary: get job args + operationId: getJobArgs + tags: + - job + parameters: + - $ref: "#/components/parameters/WorkspaceId" + - $ref: "#/components/parameters/JobId" + responses: + "200": + description: job args + content: + application/json: + schema: {} + /w/{workspace}/jobs_u/getupdate/{id}: get: summary: get job updates diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 5597d601b5..ccc65ceffc 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -266,6 +266,7 @@ pub fn global_service() -> Router { .route("/get_root_job_id/:id", get(get_root_job)) .route("/get/:id", get(get_job)) .route("/get_logs/:id", get(get_job_logs)) + .route("/get_args/:id", get(get_args)) .route("/get_flow_debug_info/:id", get(get_flow_job_debug_info)) .route("/completed/get/:id", get(get_completed_job)) .route("/completed/get_result/:id", get(get_completed_job_result)) @@ -906,6 +907,58 @@ async fn get_job_logs( } } +#[derive(FromRow)] +pub struct RawArgs { + pub args: Option>>, + pub created_by: String, +} + +async fn get_args( + OptAuthed(opt_authed): OptAuthed, + Extension(db): Extension, + Path((w_id, id)): Path<(String, Uuid)>, +) -> error::JsonResult> { + let record = sqlx::query( + "SELECT created_by, args + FROM completed_job + WHERE completed_job.id = $1 AND completed_job.workspace_id = $2", + ) + .bind(&id) + .bind(&w_id) + .fetch_optional(&db) + .await?; + + if let Some(record) = record { + let record = RawArgs::from_row(&record) + .map_err(|e| Error::InternalErr(format!("error parsing args: {e:#}")))?; + if opt_authed.is_none() && record.created_by != "anonymous" { + return Err(Error::BadRequest( + "As a non logged in user, you can only see jobs ran by anonymous users".to_string(), + )); + } + Ok(Json(record.args.map(|x| x.0).unwrap_or_default())) + } else { + let record = sqlx::query( + "SELECT created_by, args + FROM queue + WHERE queue.id = $1 AND queue.workspace_id = $2", + ) + .bind(&id) + .bind(&w_id) + .fetch_optional(&db) + .await?; + let record = not_found_if_none(record, "Job Args", id.to_string())?; + let record = RawArgs::from_row(&record) + .map_err(|e| Error::InternalErr(format!("error parsing args: {e:#}")))?; + if opt_authed.is_none() && record.created_by != "anonymous" { + return Err(Error::BadRequest( + "As a non logged in user, you can only see jobs ran by anonymous users".to_string(), + )); + } + Ok(Json(record.args.map(|x| x.0).unwrap_or_default())) + } +} + #[derive(Debug, sqlx::FromRow, Serialize)] pub struct ListableCompletedJob { pub r#type: String, diff --git a/frontend/src/lib/components/FlowStatusViewerInner.svelte b/frontend/src/lib/components/FlowStatusViewerInner.svelte index df284397f3..327335f41a 100644 --- a/frontend/src/lib/components/FlowStatusViewerInner.svelte +++ b/frontend/src/lib/components/FlowStatusViewerInner.svelte @@ -340,7 +340,7 @@ if (modId) { if ($flowStateStore && $flowStateStore?.[modId] == undefined) { $flowStateStore[modId] = { - ...$flowStateStore[modId], + ...($flowStateStore[modId] ?? {}), previewResult: jobLoaded.args } } @@ -854,7 +854,11 @@ {:else if selectedNode == 'start'} {#if job.args}
- +
{:else}

No arguments

@@ -883,7 +887,11 @@ {#if !node.isListJob}
- +
{/if} -
- - - - {argLabel ?? 'Arg'} - Value - - - - - +{#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 s3. Please download the JSON file to view them. +{:else} +
+ + + + {argLabel ?? 'Arg'} + Value + + + + + - - {#if args && Object.keys(args).length > 0} - {#each Object.entries(args).sort((a, b) => a[0].localeCompare(b[0])) as [arg, value]} + + {#if args && Object.keys(args).length > 0} + {#each Object.entries(args).sort((a, b) => a[0].localeCompare(b[0])) as [arg, value]} + + {arg} + + + {/each} + {:else if args} + No arguments + {:else} - {arg} - + + + + + + - {/each} - {:else if args} - No arguments - {:else} - - - - - - - - - {/if} - - -
+ {/if} + +
+
+{/if} @@ -99,7 +109,9 @@ ${Object.entries(args)