From eeb6b8280aca2ee97ba05aeb7125873f6e483213 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 15 Nov 2023 13:13:18 +0100 Subject: [PATCH] fix: fix delete schedule clear jobs --- ...8d5c431d841b6d5d0d99ce3836bb42d4d83d9.json | 23 ------------ ...46d313f6ef05062ac55f7397caf8c02ccec5e.json | 37 ------------------- ...ebeb2513ad58b03ab526df148582264fb3a44.json | 15 ++++++++ backend/windmill-api/src/flows.rs | 2 +- backend/windmill-api/src/schedule.rs | 26 +++---------- backend/windmill-api/src/scripts.rs | 2 +- .../(root)/(logged)/schedules/+page.svelte | 24 ++++++++---- 7 files changed, 38 insertions(+), 91 deletions(-) delete mode 100644 backend/.sqlx/query-56839d3aec6c0177d14589aedda8d5c431d841b6d5d0d99ce3836bb42d4d83d9.json delete mode 100644 backend/.sqlx/query-6dbf0275e52d937a114ba305c6646d313f6ef05062ac55f7397caf8c02ccec5e.json create mode 100644 backend/.sqlx/query-ade89de6e8527c543b182229f1febeb2513ad58b03ab526df148582264fb3a44.json diff --git a/backend/.sqlx/query-56839d3aec6c0177d14589aedda8d5c431d841b6d5d0d99ce3836bb42d4d83d9.json b/backend/.sqlx/query-56839d3aec6c0177d14589aedda8d5c431d841b6d5d0d99ce3836bb42d4d83d9.json deleted file mode 100644 index d590fbea8b..0000000000 --- a/backend/.sqlx/query-56839d3aec6c0177d14589aedda8d5c431d841b6d5d0d99ce3836bb42d4d83d9.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT is_flow FROM schedule WHERE path = $1 AND workspace_id = $2", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "is_flow", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Text", - "Text" - ] - }, - "nullable": [ - false - ] - }, - "hash": "56839d3aec6c0177d14589aedda8d5c431d841b6d5d0d99ce3836bb42d4d83d9" -} diff --git a/backend/.sqlx/query-6dbf0275e52d937a114ba305c6646d313f6ef05062ac55f7397caf8c02ccec5e.json b/backend/.sqlx/query-6dbf0275e52d937a114ba305c6646d313f6ef05062ac55f7397caf8c02ccec5e.json deleted file mode 100644 index 9344caf4c3..0000000000 --- a/backend/.sqlx/query-6dbf0275e52d937a114ba305c6646d313f6ef05062ac55f7397caf8c02ccec5e.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "DELETE FROM queue WHERE schedule_path = $1 AND running = false AND job_kind = $2 AND workspace_id = $3", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - { - "Custom": { - "name": "job_kind", - "kind": { - "Enum": [ - "script", - "preview", - "flow", - "dependencies", - "flowpreview", - "script_hub", - "identity", - "flowdependencies", - "http", - "graphql", - "postgresql", - "noop", - "appdependencies" - ] - } - } - }, - "Text" - ] - }, - "nullable": [] - }, - "hash": "6dbf0275e52d937a114ba305c6646d313f6ef05062ac55f7397caf8c02ccec5e" -} diff --git a/backend/.sqlx/query-ade89de6e8527c543b182229f1febeb2513ad58b03ab526df148582264fb3a44.json b/backend/.sqlx/query-ade89de6e8527c543b182229f1febeb2513ad58b03ab526df148582264fb3a44.json new file mode 100644 index 0000000000..2ad7c42e2f --- /dev/null +++ b/backend/.sqlx/query-ade89de6e8527c543b182229f1febeb2513ad58b03ab526df148582264fb3a44.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queue WHERE schedule_path = $1 AND running = false AND workspace_id = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "ade89de6e8527c543b182229f1febeb2513ad58b03ab526df148582264fb3a44" +} diff --git a/backend/windmill-api/src/flows.rs b/backend/windmill-api/src/flows.rs index 58b7a2d9e5..a33cbd66cd 100644 --- a/backend/windmill-api/src/flows.rs +++ b/backend/windmill-api/src/flows.rs @@ -518,7 +518,7 @@ async fn update_flow( } for schedule in schedulables.into_iter() { - clear_schedule(tx.transaction_mut(), &schedule.path, true, &w_id).await?; + clear_schedule(tx.transaction_mut(), &schedule.path, &w_id).await?; if schedule.enabled { tx = push_scheduled_job(&db, tx, schedule).await?; diff --git a/backend/windmill-api/src/schedule.rs b/backend/windmill-api/src/schedule.rs index 9d3cdb65b6..a3da6dfb8d 100644 --- a/backend/windmill-api/src/schedule.rs +++ b/backend/windmill-api/src/schedule.rs @@ -26,7 +26,6 @@ use windmill_audit::{audit_log, ActionKind}; use windmill_common::{ db::UserDB, error::{Error, JsonResult, Result}, - jobs::JobKind, schedule::Schedule, utils::{not_found_if_none, paginate, Pagination, StripPath}, }; @@ -217,17 +216,7 @@ async fn edit_schedule( cron::Schedule::from_str(&es.schedule).map_err(|e| Error::BadRequest(e.to_string()))?; - let is_flow = sqlx::query_scalar!( - "SELECT is_flow FROM schedule WHERE path = $1 AND workspace_id = $2", - path, - w_id - ) - .fetch_optional(&mut tx) - .await?; - - let is_flow = not_found_if_none(is_flow, "Schedule", &path)?; - - clear_schedule(tx.transaction_mut(), path, is_flow, &w_id).await?; + clear_schedule(tx.transaction_mut(), path, &w_id).await?; let schedule = sqlx::query_as!( Schedule, "UPDATE schedule SET schedule = $1, timezone = $2, args = $3, on_failure = $4, on_failure_times = $5, on_failure_exact = $6, on_failure_extra_args = $7, on_recovery = $8, on_recovery_times = $9, on_recovery_extra_args = $10, ws_error_handler_muted = $11 @@ -442,7 +431,7 @@ pub async fn set_enabled( let schedule = not_found_if_none(schedule_o, "Schedule", path)?; - clear_schedule(tx.transaction_mut(), path, schedule.is_flow, &w_id).await?; + clear_schedule(tx.transaction_mut(), path, &w_id).await?; audit_log( &mut tx, @@ -474,6 +463,8 @@ async fn delete_schedule( let mut tx = user_db.begin(&authed).await?; let path = path.to_path(); + clear_schedule(&mut tx, path, &w_id).await?; + sqlx::query!( "DELETE FROM schedule WHERE path = $1 AND workspace_id = $2", path, @@ -635,18 +626,11 @@ pub struct EditSchedule { pub async fn clear_schedule<'c>( db: &mut Transaction<'c, Postgres>, path: &str, - is_flow: bool, w_id: &str, ) -> Result<()> { - let job_kind = if is_flow { - JobKind::Flow - } else { - JobKind::Script - }; sqlx::query!( - "DELETE FROM queue WHERE schedule_path = $1 AND running = false AND job_kind = $2 AND workspace_id = $3", + "DELETE FROM queue WHERE schedule_path = $1 AND running = false AND workspace_id = $2", path, - job_kind as JobKind, w_id ) .execute(&mut **db) diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 0fe732dd7f..c07e1b806a 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -525,7 +525,7 @@ async fn create_script( } for schedule in schedulables { - clear_schedule(tx.transaction_mut(), &schedule.path, false, &w_id).await?; + clear_schedule(tx.transaction_mut(), &schedule.path, &w_id).await?; if schedule.enabled { tx = push_scheduled_job(&db, tx, schedule).await?; diff --git a/frontend/src/routes/(root)/(logged)/schedules/+page.svelte b/frontend/src/routes/(root)/(logged)/schedules/+page.svelte index 6c43287098..a985037cde 100644 --- a/frontend/src/routes/(root)/(logged)/schedules/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/schedules/+page.svelte @@ -27,14 +27,22 @@ let loadingSchedulesWithJobStats = true async function loadSchedules(): Promise { - schedules = (await ScheduleService.listSchedules({ workspace: $workspaceStore! })).map((x) => { - return { canWrite: canWrite(x.path, x.extra_perms!, $userStore), ...x } - }) - loading = false - // after the schedule core data has been loaded, load all the job stats - // TODO: we could potentially not reload the job stats on every call to loadSchedules, but for now it's - // simpler to always call it. Update if performance becomes an issue. - loadSchedulesWithJobStats() + loading = true + try { + schedules = (await ScheduleService.listSchedules({ workspace: $workspaceStore! })).map( + (x) => { + return { canWrite: canWrite(x.path, x.extra_perms!, $userStore), ...x } + } + ) + loading = false + // after the schedule core data has been loaded, load all the job stats + // TODO: we could potentially not reload the job stats on every call to loadSchedules, but for now it's + // simpler to always call it. Update if performance becomes an issue. + loadSchedulesWithJobStats() + } catch (e) { + loading = false + throw e + } } async function loadSchedulesWithJobStats(): Promise {