fix: fix delete schedule clear jobs

This commit is contained in:
Ruben Fiszel
2023-11-15 13:13:18 +01:00
parent 67d6b269dd
commit eeb6b8280a
7 changed files with 38 additions and 91 deletions
@@ -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"
}
@@ -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"
}
@@ -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"
}
+1 -1
View File
@@ -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?;
+5 -21
View File
@@ -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)
+1 -1
View File
@@ -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?;
@@ -27,14 +27,22 @@
let loadingSchedulesWithJobStats = true
async function loadSchedules(): Promise<void> {
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<void> {