diff --git a/internal/pkg/core/deployer/providers/k8s-secret/k8s_secret.go b/internal/pkg/core/deployer/providers/k8s-secret/k8s_secret.go index f09e8331..9e74e794 100644 --- a/internal/pkg/core/deployer/providers/k8s-secret/k8s_secret.go +++ b/internal/pkg/core/deployer/providers/k8s-secret/k8s_secret.go @@ -65,6 +65,9 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context, certPem string, privkeyP if d.config.SecretName == "" { return nil, errors.New("config `secretName` is required") } + if d.config.SecretType == "" { + return nil, errors.New("config `secretType` is required") + } if d.config.SecretDataKeyForCrt == "" { return nil, errors.New("config `secretDataKeyForCrt` is required") } diff --git a/ui/src/api/workflow.ts b/ui/src/api/workflow.ts index d545b94e..c40fcce8 100644 --- a/ui/src/api/workflow.ts +++ b/ui/src/api/workflow.ts @@ -1,7 +1,6 @@ -import type { RecordModel, RecordSubscription } from "pocketbase"; -import { ClientResponseError } from "pocketbase"; +import { ClientResponseError, type RecordSubscription } from "pocketbase"; -import { WORKFLOW_TRIGGERS } from "@/domain/workflow"; +import { WORKFLOW_TRIGGERS, type WorkflowModel } from "@/domain/workflow"; import { getPocketBase } from "@/repository/pocketbase"; export const run = async (id: string) => { @@ -25,14 +24,14 @@ export const run = async (id: string) => { return resp; }; -export const subscribe = async (id: string, cb: (e: RecordSubscription) => void) => { +export const subscribe = async (id: string, cb: (e: RecordSubscription) => void) => { const pb = getPocketBase(); - pb.collection("workflow").subscribe(id, cb); + return pb.collection("workflow").subscribe(id, cb); }; export const unsubscribe = async (id: string) => { const pb = getPocketBase(); - pb.collection("workflow").unsubscribe(id); + return pb.collection("workflow").unsubscribe(id); }; diff --git a/ui/src/hooks/useZustandShallowSelector.ts b/ui/src/hooks/useZustandShallowSelector.ts index 724cdf2c..23b23666 100644 --- a/ui/src/hooks/useZustandShallowSelector.ts +++ b/ui/src/hooks/useZustandShallowSelector.ts @@ -18,11 +18,11 @@ export type UseZustandShallowSelectorReturns ({ + * const { foo, bar, baz } = useStore(useShallow((state) => ({ * foo: state.foo, * bar: state.bar, * baz: state.baz, - * })); + * }))); * ``` */ const useZustandShallowSelector = (paths: MaybeMany): UseZustandShallowSelectorReturns => { diff --git a/ui/src/pages/workflows/WorkflowDetail.tsx b/ui/src/pages/workflows/WorkflowDetail.tsx index 0d89ac2a..cc5fba5b 100644 --- a/ui/src/pages/workflows/WorkflowDetail.tsx +++ b/ui/src/pages/workflows/WorkflowDetail.tsx @@ -13,16 +13,16 @@ import { import { PageHeader } from "@ant-design/pro-components"; import { Alert, Button, Card, Dropdown, Form, Input, Modal, Space, Tabs, Typography, message, notification } from "antd"; import { createSchemaFieldRule } from "antd-zod"; -import { ClientResponseError } from "pocketbase"; import { isEqual } from "radash"; import { z } from "zod"; -import { run as runWorkflow, subscribe, unsubscribe } from "@/api/workflow"; +import { run as runWorkflow, subscribe as subscribeWorkflow, unsubscribe as unsubscribeWorkflow } from "@/api/workflow"; import ModalForm from "@/components/ModalForm"; import Show from "@/components/Show"; import WorkflowElements from "@/components/workflow/WorkflowElements"; import WorkflowRuns from "@/components/workflow/WorkflowRuns"; import { isAllNodesValidated } from "@/domain/workflow"; +import { WORKFLOW_RUN_STATUSES } from "@/domain/workflowRun"; import { useAntdForm, useZustandShallowSelector } from "@/hooks"; import { remove as removeWorkflow } from "@/repository/workflow"; import { useWorkflowStore } from "@/stores/workflow"; @@ -63,21 +63,21 @@ const WorkflowDetail = () => { }, [workflow]); useEffect(() => { - if (lastRunStatus && lastRunStatus == "running") { - setIsRunning(true); - } else { - setIsRunning(false); - } + setIsRunning(lastRunStatus == WORKFLOW_RUN_STATUSES.RUNNING); }, [lastRunStatus]); useEffect(() => { - if (isRunning && workflowId) { - subscribe(workflowId, (e) => { - if (e.record.lastRunStatus !== "running") { + if (!!workflowId && isRunning) { + subscribeWorkflow(workflowId, (e) => { + if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) { setIsRunning(false); - unsubscribe(workflowId); + unsubscribeWorkflow(workflowId); } }); + + return () => { + unsubscribeWorkflow(workflowId); + }; } }, [workflowId, isRunning]); @@ -174,26 +174,28 @@ const WorkflowDetail = () => { } promise.then(async () => { + let unsubscribeFn: Awaited> | undefined = undefined; + try { + setIsRunning(true); + // subscribe before running workflow - subscribe(workflowId!, (e) => { - if (e.record.lastRunStatus !== "running") { + unsubscribeFn = await subscribeWorkflow(workflowId!, (e) => { + if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) { setIsRunning(false); - unsubscribe(workflowId!); + unsubscribeFn?.(); } }); + await runWorkflow(workflowId!); - setIsRunning(true); messageApi.success(t("common.text.operation_succeeded")); } catch (err) { - if (err instanceof ClientResponseError && err.isAbort) { - return; - } + setIsRunning(false); + unsubscribeFn?.(); console.error(err); messageApi.warning(t("common.text.operation_failed")); - setIsRunning(false); } }); };