From 050daee33dfad8d8d7f960729fe415282bddacd5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 21 Nov 2023 17:58:26 +0100 Subject: [PATCH] fix: fix flow primary schedule clearing --- backend/windmill-api/src/flows.rs | 1 + .../src/lib/components/FlowBuilder.svelte | 64 ++++++++++--------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/backend/windmill-api/src/flows.rs b/backend/windmill-api/src/flows.rs index 6be0b3f81b..74ea2b2bd8 100644 --- a/backend/windmill-api/src/flows.rs +++ b/backend/windmill-api/src/flows.rs @@ -520,6 +520,7 @@ async fn update_flow( .await?; if let Some(schedule) = schedule { + clear_schedule(tx.transaction_mut(), &flow_path, &w_id).await?; schedulables.push(schedule); } diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index ad1a1d2587..edab9ebd79 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -221,6 +221,40 @@ } } else { localStorage.removeItem(`flow-${initialPath}`) + + const scheduleExists = await ScheduleService.existsSchedule({ + workspace: $workspaceStore ?? '', + path: initialPath + }) + + let createScheduleAfterFlow = false + if (scheduleExists) { + const schedule = await ScheduleService.getSchedule({ + workspace: $workspaceStore ?? '', + path: initialPath + }) + if (JSON.stringify(schedule.args) != JSON.stringify(args) || schedule.schedule != cron) { + await ScheduleService.updateSchedule({ + workspace: $workspaceStore ?? '', + path: initialPath, + requestBody: { + schedule: formatCron(cron), + timezone, + args + } + }) + } + if (enabled != schedule.enabled) { + await ScheduleService.setScheduleEnabled({ + workspace: $workspaceStore ?? '', + path: initialPath, + requestBody: { enabled } + }) + } + } else if (enabled) { + await createSchedule(initialPath) + } + await FlowService.updateFlow({ workspace: $workspaceStore!, path: initialPath, @@ -235,36 +269,6 @@ ws_error_handler_muted: flow.ws_error_handler_muted } }) - const scheduleExists = await ScheduleService.existsSchedule({ - workspace: $workspaceStore ?? '', - path: $pathStore - }) - if (scheduleExists) { - const schedule = await ScheduleService.getSchedule({ - workspace: $workspaceStore ?? '', - path: $pathStore - }) - if (JSON.stringify(schedule.args) != JSON.stringify(args) || schedule.schedule != cron) { - await ScheduleService.updateSchedule({ - workspace: $workspaceStore ?? '', - path: $pathStore, - requestBody: { - schedule: formatCron(cron), - timezone, - args - } - }) - } - if (enabled != schedule.enabled) { - await ScheduleService.setScheduleEnabled({ - workspace: $workspaceStore ?? '', - path: $pathStore, - requestBody: { enabled } - }) - } - } else if (enabled) { - await createSchedule($pathStore) - } } savedFlow = { ...cloneDeep($flowStore),