From dd4f48d2448984e79f132d978926ec70c2039bf5 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Thu, 28 Mar 2024 15:50:18 +0100 Subject: [PATCH] fix: show start to finish time for flows instead of cumulative (#3486) * fix: show start to finish time for flows instead of cumulative * fix: build --- ...3ff66b37ed8110a0b67aedb9f25e6a7383e1.json} | 5 +- ...f8f764aa4686e7df9c53d30d49a3dbbf36af4.json | 22 --------- backend/windmill-queue/src/jobs.rs | 48 +------------------ frontend/src/lib/components/DurationMs.svelte | 11 +---- frontend/src/lib/components/JobStatus.svelte | 10 +--- .../src/lib/components/jobs/JobPreview.svelte | 5 +- .../src/lib/components/runs/JobPreview.svelte | 5 +- 7 files changed, 9 insertions(+), 97 deletions(-) rename backend/.sqlx/{query-2ade671449393541fa565088b21268dad137314d250f7ded502defb9a6de0b2f.json => query-d5a8614286c170e0d175903cd1b53ff66b37ed8110a0b67aedb9f25e6a7383e1.json} (87%) delete mode 100644 backend/.sqlx/query-f516ca558816c2cbab3c8ae865ef8f764aa4686e7df9c53d30d49a3dbbf36af4.json diff --git a/backend/.sqlx/query-2ade671449393541fa565088b21268dad137314d250f7ded502defb9a6de0b2f.json b/backend/.sqlx/query-d5a8614286c170e0d175903cd1b53ff66b37ed8110a0b67aedb9f25e6a7383e1.json similarity index 87% rename from backend/.sqlx/query-2ade671449393541fa565088b21268dad137314d250f7ded502defb9a6de0b2f.json rename to backend/.sqlx/query-d5a8614286c170e0d175903cd1b53ff66b37ed8110a0b67aedb9f25e6a7383e1.json index c349ba77e5..a9e46342cc 100644 --- a/backend/.sqlx/query-2ade671449393541fa565088b21268dad137314d250f7ded502defb9a6de0b2f.json +++ b/backend/.sqlx/query-d5a8614286c170e0d175903cd1b53ff66b37ed8110a0b67aedb9f25e6a7383e1.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO completed_job AS cj\n ( workspace_id\n , id\n , parent_job\n , created_by\n , created_at\n , started_at\n , duration_ms\n , success\n , script_hash\n , script_path\n , args\n , result\n , raw_code\n , raw_lock\n , canceled\n , canceled_by\n , canceled_reason\n , job_kind\n , schedule_path\n , permissioned_as\n , flow_status\n , raw_flow\n , is_flow_step\n , is_skipped\n , language\n , email\n , visible_to_owner\n , mem_peak\n , tag\n , priority\n )\n VALUES ($1, $2, $3, $4, $5, COALESCE($6, now()), COALESCE($25, (EXTRACT('epoch' FROM (now())) - EXTRACT('epoch' FROM (COALESCE($6, now()))))*1000), $7, $8, $9,$10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $26, $27, $28, $29, $30)\n ON CONFLICT (id) DO UPDATE SET success = $7, result = $11 RETURNING duration_ms", + "query": "INSERT INTO completed_job AS cj\n ( workspace_id\n , id\n , parent_job\n , created_by\n , created_at\n , started_at\n , duration_ms\n , success\n , script_hash\n , script_path\n , args\n , result\n , raw_code\n , raw_lock\n , canceled\n , canceled_by\n , canceled_reason\n , job_kind\n , schedule_path\n , permissioned_as\n , flow_status\n , raw_flow\n , is_flow_step\n , is_skipped\n , language\n , email\n , visible_to_owner\n , mem_peak\n , tag\n , priority\n )\n VALUES ($1, $2, $3, $4, $5, COALESCE($6, now()), (EXTRACT('epoch' FROM (now())) - EXTRACT('epoch' FROM (COALESCE($6, now()))))*1000, $7, $8, $9,$10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29)\n ON CONFLICT (id) DO UPDATE SET success = $7, result = $11 RETURNING duration_ms", "describe": { "columns": [ { @@ -79,7 +79,6 @@ } } }, - "Numeric", "Varchar", "Bool", "Int4", @@ -91,5 +90,5 @@ false ] }, - "hash": "2ade671449393541fa565088b21268dad137314d250f7ded502defb9a6de0b2f" + "hash": "d5a8614286c170e0d175903cd1b53ff66b37ed8110a0b67aedb9f25e6a7383e1" } diff --git a/backend/.sqlx/query-f516ca558816c2cbab3c8ae865ef8f764aa4686e7df9c53d30d49a3dbbf36af4.json b/backend/.sqlx/query-f516ca558816c2cbab3c8ae865ef8f764aa4686e7df9c53d30d49a3dbbf36af4.json deleted file mode 100644 index fe3add8d5e..0000000000 --- a/backend/.sqlx/query-f516ca558816c2cbab3c8ae865ef8f764aa4686e7df9c53d30d49a3dbbf36af4.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT SUM(duration_ms) as duration FROM completed_job WHERE id = ANY($1)", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "duration", - "type_info": "Numeric" - } - ], - "parameters": { - "Left": [ - "UuidArray" - ] - }, - "nullable": [ - null - ] - }, - "hash": "f516ca558816c2cbab3c8ae865ef8f764aa4686e7df9c53d30d49a3dbbf36af4" -} diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index ba853311cf..4c897f86a6 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -21,7 +21,6 @@ use axum::{ http::{request::Parts, Request, Uri}, response::{IntoResponse, Response}, }; -use bigdecimal::ToPrimitive; use chrono::{DateTime, Duration, Utc}; use itertools::Itertools; #[cfg(feature = "prometheus")] @@ -440,24 +439,6 @@ pub async fn add_completed_job_error) -> Vec { - modules - .into_iter() - .filter_map(|m| match m { - FlowStatusModule::Success { job, flow_jobs, .. } - | FlowStatusModule::Failure { job, flow_jobs, .. } => { - if let Some(flow_jobs) = flow_jobs { - Some(flow_jobs) - } else { - Some(vec![job]) - } - } - _ => None, - }) - .flatten() - .collect::>() -} - lazy_static::lazy_static! { pub static ref GLOBAL_ERROR_HANDLER_PATH_IN_ADMINS_WORKSPACE: Option = std::env::var("GLOBAL_ERROR_HANDLER_PATH_IN_ADMINS_WORKSPACE").ok(); } @@ -487,30 +468,6 @@ pub async fn add_completed_job< } let is_flow = queued_job.is_flow(); - let duration = if is_flow { - let jobs = queued_job.parse_flow_status().map(|s| { - let mut modules = s.modules; - modules.extend([s.failure_module.module_status]); - flatten_jobs(modules) - }); - if let Some(jobs) = jobs { - sqlx::query_scalar!( - "SELECT SUM(duration_ms) as duration FROM completed_job WHERE id = ANY($1)", - jobs.as_slice() - ) - .fetch_one(db) - .await - .ok() - .flatten() - .map(|x| x.to_i64()) - .flatten() - } else { - tracing::warn!("Could not parse flow status"); - None - } - } else { - None - }; let mut tx: QueueTransaction<'_, R> = (rsmq.clone(), db.begin().await?).into(); let job_id = queued_job.id; @@ -556,8 +513,8 @@ pub async fn add_completed_job< , tag , priority ) - VALUES ($1, $2, $3, $4, $5, COALESCE($6, now()), COALESCE($25, (EXTRACT('epoch' FROM (now())) - EXTRACT('epoch' FROM (COALESCE($6, now()))))*1000), $7, $8, $9,\ - $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $26, $27, $28, $29, $30) + VALUES ($1, $2, $3, $4, $5, COALESCE($6, now()), (EXTRACT('epoch' FROM (now())) - EXTRACT('epoch' FROM (COALESCE($6, now()))))*1000, $7, $8, $9,\ + $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29) ON CONFLICT (id) DO UPDATE SET success = $7, result = $11 RETURNING duration_ms", queued_job.workspace_id, queued_job.id, @@ -583,7 +540,6 @@ pub async fn add_completed_job< queued_job.is_flow_step, skipped, queued_job.language.clone() as Option, - duration as Option, queued_job.email, queued_job.visible_to_owner, if mem_peak > 0 { Some(mem_peak) } else { None }, diff --git a/frontend/src/lib/components/DurationMs.svelte b/frontend/src/lib/components/DurationMs.svelte index f84031f3a3..8ef8472120 100644 --- a/frontend/src/lib/components/DurationMs.svelte +++ b/frontend/src/lib/components/DurationMs.svelte @@ -1,20 +1,11 @@ - Ran in {msToSec(duration_ms)}s {#if flow}(sum){/if} - {#if flow} - - Cumulative time of the execution of each steps. Suspend/sleep/transition times are not - accounted for, and each step's duration in a parallel branch would be added. Hence the time - here can differ from the time it took for the flow to have a result from start. - - {/if} + Ran in {msToSec(duration_ms)}s diff --git a/frontend/src/lib/components/JobStatus.svelte b/frontend/src/lib/components/JobStatus.svelte index 5039d494f2..601e559afe 100644 --- a/frontend/src/lib/components/JobStatus.svelte +++ b/frontend/src/lib/components/JobStatus.svelte @@ -17,18 +17,12 @@ Success {job.is_skipped ? '(Skipped)' : ''} - + {:else if job && 'success' in job}
Failed - +
{:else if job && 'running' in job && job.running}
diff --git a/frontend/src/lib/components/jobs/JobPreview.svelte b/frontend/src/lib/components/jobs/JobPreview.svelte index 846c19ab64..3f56942707 100644 --- a/frontend/src/lib/components/jobs/JobPreview.svelte +++ b/frontend/src/lib/components/jobs/JobPreview.svelte @@ -108,10 +108,7 @@ Mem: {job?.['mem_peak'] ? `${(job['mem_peak'] / 1024).toPrecision(4)}MB` : 'N/A'} {#if job?.['duration_ms']} - + {/if}
diff --git a/frontend/src/lib/components/runs/JobPreview.svelte b/frontend/src/lib/components/runs/JobPreview.svelte index 3569054789..36fa23e88c 100644 --- a/frontend/src/lib/components/runs/JobPreview.svelte +++ b/frontend/src/lib/components/runs/JobPreview.svelte @@ -62,10 +62,7 @@ {/if} {#if job && 'duration_ms' in job && job.duration_ms != undefined} - + {/if} {#if job?.['mem_peak']}