From 51ebce6741b3c983bca247c8df9f1c72dcb5eb96 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 19 Jan 2024 20:22:20 +0100 Subject: [PATCH] improve app handling of job with error keys --- backend/windmill-api/openapi.yaml | 2 + backend/windmill-api/src/job_helpers.rs | 2 +- backend/windmill-api/src/jobs.rs | 45 ++++++++++++------- .../src/lib/components/ResultJobLoader.svelte | 5 ++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index fe79335c67..d15c7693ec 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -5035,6 +5035,8 @@ paths: completed: type: boolean result: {} + success: + type: boolean started: type: boolean required: diff --git a/backend/windmill-api/src/job_helpers.rs b/backend/windmill-api/src/job_helpers.rs index de6b42618d..5ceb0cf0b8 100644 --- a/backend/windmill-api/src/job_helpers.rs +++ b/backend/windmill-api/src/job_helpers.rs @@ -794,7 +794,7 @@ async fn multipart_upload_s3_file( .unwrap_or_default() .as_millis(), rand::random::(), - query.file_extension.unwrap_or("file".to_string()) + query.file_extension.clone().unwrap_or("file".to_string()) ) .to_string() } diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 7439dd005e..e2805c20e5 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -3130,6 +3130,12 @@ pub struct RawResult<'a> { pub result: &'a JsonRawValue, } +#[derive(FromRow)] +pub struct RawResultWithSuccess<'a> { + pub result: &'a JsonRawValue, + pub success: bool, +} + impl<'a> IntoResponse for RawResult<'a> { fn into_response(self) -> Response { Json(self.result).into_response() @@ -3170,6 +3176,7 @@ async fn get_completed_job_result( #[derive(Serialize)] struct CompletedJobResult<'c> { started: Option, + success: Option, completed: bool, result: Option<&'c JsonRawValue>, } @@ -3184,17 +3191,19 @@ async fn get_completed_job_result_maybe( Path((w_id, id)): Path<(String, Uuid)>, Query(GetCompletedJobQuery { get_started }): Query, ) -> error::Result { - let result_o = - sqlx::query("SELECT result FROM completed_job WHERE id = $1 AND workspace_id = $2") - .bind(id) - .bind(&w_id) - .fetch_optional(&db) - .await?; + let result_o = sqlx::query( + "SELECT result, success FROM completed_job WHERE id = $1 AND workspace_id = $2", + ) + .bind(id) + .bind(&w_id) + .fetch_optional(&db) + .await?; if let Some(result) = result_o { - let res = RawResult::from_row(&result)?; + let res = RawResultWithSuccess::from_row(&result)?; Ok(Json(CompletedJobResult { started: Some(true), + success: Some(res.success), completed: true, result: Some(res.result), }) @@ -3208,15 +3217,21 @@ async fn get_completed_job_result_maybe( .fetch_optional(&db) .await? .unwrap_or(false); - Ok( - Json(CompletedJobResult { started: Some(started), completed: false, result: None }) - .into_response(), - ) + Ok(Json(CompletedJobResult { + started: Some(started), + completed: false, + success: None, + result: None, + }) + .into_response()) } else { - Ok( - Json(CompletedJobResult { started: None, completed: false, result: None }) - .into_response(), - ) + Ok(Json(CompletedJobResult { + started: None, + completed: false, + success: None, + result: None, + }) + .into_response()) } } diff --git a/frontend/src/lib/components/ResultJobLoader.svelte b/frontend/src/lib/components/ResultJobLoader.svelte index 8a196a06c7..03a8ee80ee 100644 --- a/frontend/src/lib/components/ResultJobLoader.svelte +++ b/frontend/src/lib/components/ResultJobLoader.svelte @@ -7,7 +7,8 @@ import type { SupportedLanguage } from '$lib/common' export let isLoading = false - export let job: { completed: boolean; result: any; id: string } | undefined = undefined + export let job: { completed: boolean; result: any; id: string; success?: boolean } | undefined = + undefined export let workspaceOverride: string | undefined = undefined export let notfound = false export let isEditor = false @@ -177,7 +178,7 @@ if (currentId === id || allowConcurentRequests) { job = { ...maybe_job, id } await tick() - if (typeof job?.result == 'object' && 'error' in (job?.result ?? {})) { + if (!job?.success && typeof job?.result == 'object' && 'error' in (job?.result ?? {})) { callbacks?.error() dispatch('doneError', { id,