From dc935fa0549b7e09ec48289e07708cc72a3736ef Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 3 Jan 2023 15:56:02 +0100 Subject: [PATCH] fix forking hub deno scripts in apps --- backend/windmill-api/src/jobs.rs | 54 ++++++++++++++++--- .../apps/components/table/AppTable.svelte | 10 +++- .../InlineScriptEditorPanel.svelte | 12 ++++- frontend/src/lib/components/apps/utils.ts | 3 ++ .../propertyPicker/ObjectViewer.svelte | 9 +++- 5 files changed, 76 insertions(+), 12 deletions(-) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index ac8afe9073..4e46abb110 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -19,7 +19,7 @@ use hmac::Mac; use hyper::{HeaderMap, StatusCode}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use sql_builder::{prelude::*, quote, SqlBuilder}; -use sqlx::{query_scalar, types::Uuid, Postgres, Transaction}; +use sqlx::{query_scalar, types::Uuid, FromRow, Postgres, Transaction}; use urlencoding::encode; use windmill_audit::{audit_log, ActionKind}; use windmill_common::{ @@ -338,9 +338,9 @@ fn list_queue_jobs_query(w_id: &str, lq: &ListQueueQuery, fields: &[&str]) -> Sq } if let Some(s) = &lq.suspended { if *s { - sqlb.and_where_is_not_null("suspend"); + sqlb.and_where_gt("suspend", 0); } else { - sqlb.and_where_is_null("suspend"); + sqlb.and_where_eq("suspend", 0); } } if let Some(jk) = &lq.job_kinds { @@ -353,13 +353,55 @@ fn list_queue_jobs_query(w_id: &str, lq: &ListQueueQuery, fields: &[&str]) -> Sq sqlb } +#[derive(Serialize, FromRow)] +struct ListableQueuedJob { + pub id: Uuid, + pub created_by: String, + pub created_at: chrono::DateTime, + pub started_at: Option>, + pub scheduled_for: chrono::DateTime, + pub script_hash: Option, + pub script_path: Option, + pub args: Option, + pub job_kind: JobKind, + pub schedule_path: Option, + pub is_flow_step: bool, + pub language: Option, + pub email: String, + pub suspend: Option, +} + async fn list_queue_jobs( Extension(db): Extension, Path(w_id): Path, Query(lq): Query, -) -> error::JsonResult> { - let sql = list_queue_jobs_query(&w_id, &lq, &["*"]).sql()?; - let jobs = sqlx::query_as::<_, QueuedJob>(&sql).fetch_all(&db).await?; +) -> error::JsonResult> { + let sql = list_queue_jobs_query( + &w_id, + &lq, + &[ + "id", + "created_by", + "created_at", + "started_at", + "scheduled_for", + "script_hash", + "script_path", + "args", + "job_kind", + "schedule_path", + "permissioned_as", + "is_flow_step", + "language", + "same_worker", + "email", + "suspend", + ], + ) + .sql()?; + let jobs = sqlx::query_as::<_, ListableQueuedJob>(&sql) + .fetch_all(&db) + .await?; Ok(Json(jobs)) } diff --git a/frontend/src/lib/components/apps/components/table/AppTable.svelte b/frontend/src/lib/components/apps/components/table/AppTable.svelte index 8ddc64e762..d0cacc9fb0 100644 --- a/frontend/src/lib/components/apps/components/table/AppTable.svelte +++ b/frontend/src/lib/components/apps/components/table/AppTable.svelte @@ -95,6 +95,10 @@ } } + function cellIsObject(x: (any) => any, props: any): boolean { + return typeof x != 'string' && typeof x(props) == 'object' + } + let filteredResult: Array> = [] $: filteredResult && setOptions(filteredResult) @@ -167,7 +171,7 @@ )} > {#each row.getVisibleCells() as cell, index (index)} - {#if cell?.column?.columnDef?.header} + {#if cell?.column?.columnDef?.cell} {@const context = cell?.getContext()} {#if context} {@const component = renderCell(cell.column.columnDef.cell, context)} @@ -175,7 +179,9 @@ on:click={() => toggleRow(row, rowIndex)} class="p-4 whitespace-nowrap text-xs text-gray-900" > - {#if component != undefined} + {#if typeof cell.column.columnDef.cell != 'string' && cellIsObject(cell.column.columnDef.cell, context)} + {JSON.stringify(cell.column.columnDef.cell(context), null, 4)} + {:else if component != undefined} {/if} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte index c40629c503..6f9c2b61e8 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte @@ -3,7 +3,9 @@ import Button from '$lib/components/common/button/Button.svelte' import FlowModuleScript from '$lib/components/flows/content/FlowModuleScript.svelte' import FlowPathViewer from '$lib/components/flows/content/FlowPathViewer.svelte' - import { getScriptByPath } from '$lib/utils' + import { inferArgs } from '$lib/infer' + import { loadSchema } from '$lib/scripts' + import { emptySchema, getScriptByPath } from '$lib/utils' import { faCodeBranch, faExternalLinkAlt, faEye, faPen } from '@fortawesome/free-solid-svg-icons' import type { AppInput, ResultAppInput } from '../../inputType' import { clearResultAppInput } from '../../utils' @@ -13,8 +15,13 @@ export let componentInput: AppInput | undefined async function fork(path: string) { - const { content, language, schema } = await getScriptByPath(path) + let { content, language, schema } = await getScriptByPath(path) if (componentInput && componentInput.type == 'runnable') { + if (!schema || Object.keys(schema).length == 0) { + schema = emptySchema() + await inferArgs(language, content, schema) + } + console.log(schema) componentInput.runnable = { type: 'runnableByName', name: path, @@ -25,6 +32,7 @@ path } } + console.log(content, language, schema) } else { console.error('componentInput is undefined') } diff --git a/frontend/src/lib/components/apps/utils.ts b/frontend/src/lib/components/apps/utils.ts index 32e2dc3008..6662943199 100644 --- a/frontend/src/lib/components/apps/utils.ts +++ b/frontend/src/lib/components/apps/utils.ts @@ -53,6 +53,9 @@ export async function loadSchema( } export function schemaToInputsSpec(schema: Schema): Record { + if (schema?.properties == undefined) { + return {} + } return Object.keys(schema.properties).reduce((accu, key) => { const property = schema.properties[key] diff --git a/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte b/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte index b7f8676a68..cd2c2a26f4 100644 --- a/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte +++ b/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte @@ -5,6 +5,7 @@ import { Badge } from '../common' import { NEVER_TESTED_THIS_FAR } from '../flows/utils' import { getTypeAsString } from '../flows/utils' + import Popover from '../Popover.svelte' import { computeKey } from './utils' import WarningMessage from './WarningMessage.svelte' @@ -90,9 +91,13 @@ {#if json[key] === NEVER_TESTED_THIS_FAR} {:else if json[key] == undefined} - undefined + undefined + {:else if typeof json[key] == 'string'} + "{truncate(json[key], 200)}" {:else} - {truncate(JSON.stringify(json[key]), 40)} + {truncate(JSON.stringify(json[key]), 200)} {/if} {/if}