From f377c84f5a2148a2bbb7c16e93f13e1d85ceb17e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 31 Jan 2023 10:21:48 +0100 Subject: [PATCH] feat: add sync webhook for flows --- backend/windmill-api/openapi.yaml | 38 ++++++++++++++ backend/windmill-api/src/jobs.rs | 51 +++++++++++++++++++ .../(logged)/flows/get/[...path]/+page.svelte | 33 +++++++++--- .../scripts/get/[...hash]/+page.svelte | 4 +- 4 files changed, 117 insertions(+), 9 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index d5be47cd7b..4d28127da3 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -2445,6 +2445,44 @@ paths: application/json: schema: {} + /w/{workspace}/jobs/run_wait_result/f/{path}: + post: + summary: run flow by path and wait until completion + operationId: runWaitResultFlowByPath + tags: + - job + parameters: + - $ref: "#/components/parameters/WorkspaceId" + - $ref: "#/components/parameters/ScriptPath" + - name: scheduled_for + description: when to schedule this job (leave empty for immediate run) + in: query + schema: + type: string + format: date-time + - name: scheduled_in_secs + description: schedule the script to execute in the number of seconds starting now + in: query + schema: + type: integer + - $ref: "#/components/parameters/IncludeHeader" + - $ref: "#/components/parameters/QueueLimit" + + requestBody: + description: script args + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ScriptArgs" + + responses: + "200": + description: job result + content: + application/json: + schema: {} + /w/{workspace}/jobs/result_by_id/{flow_job_id}/{node_id}: get: summary: get job result by id diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 78892088af..3bf1ca2769 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -53,6 +53,10 @@ pub fn workspaced_service() -> Router { "/run_wait_result/h/:hash", post(run_wait_result_job_by_hash), ) + .route( + "/run_wait_result/f/*script_path", + post(run_wait_result_flow_by_path), + ) .route("/run/h/:hash", post(run_job_by_hash)) .route("/run/preview", post(run_preview_job)) .route("/run/preview_flow", post(run_preview_flow_job)) @@ -1388,6 +1392,53 @@ pub async fn run_wait_result_job_by_hash( .await } +pub async fn run_wait_result_flow_by_path( + authed: Authed, + Extension(user_db): Extension, + Extension(db): Extension, + Extension(timeout): Extension>, + Path((w_id, flow_path)): Path<(String, StripPath)>, + Query(run_query): Query, + headers: HeaderMap, + Json(args): Json>>, +) -> error::JsonResult { + check_queue_too_long(db, run_query.queue_limit).await?; + + let flow_path = flow_path.to_path(); + let mut tx = user_db.clone().begin(&authed).await?; + let scheduled_for = run_query.get_scheduled_for(&mut tx).await?; + let args = run_query.add_include_headers(headers, args.unwrap_or_default()); + + let (uuid, tx) = push( + tx, + &w_id, + JobPayload::Flow(flow_path.to_string()), + args, + &authed.username, + &authed.email, + username_to_permissioned_as(&authed.username), + scheduled_for, + None, + run_query.parent_job, + false, + false, + None, + !run_query.invisible_to_owner.unwrap_or(false), + ) + .await?; + + tx.commit().await?; + + run_wait_result( + authed, + Extension(user_db), + timeout.0, + uuid, + Path((w_id, flow_path)), + ) + .await +} + // a similar function exists on the worker pub async fn script_path_to_payload<'c>( script_path: &str, diff --git a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte index 45a652abb2..5b5f18d908 100644 --- a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte @@ -99,7 +99,8 @@ can_write = canWrite(flow.path, flow.extra_perms!, $userStore) } - $: url = `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/f/${flow?.path}` + $: urlAsync = `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/f/${flow?.path}` + $: urlSync = `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run_wait_result/f/${flow?.path}` let runForm: RunForm | undefined let isValid = true @@ -306,21 +307,39 @@ >
- diff --git a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte index 4d51f42450..145076340b 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte @@ -445,8 +445,8 @@ - UUID - Result + UUID/Async + Result/Sync {#each Object.keys(webhooks) as key}